- Feature Articles
- CodeSOD
- Error'd
- Forums
-
Other Articles
- Random Article
- Other Series
- Alex's Soapbox
- Announcements
- Best of…
- Best of Email
- Best of the Sidebar
- Bring Your Own Code
- Coded Smorgasbord
- Mandatory Fun Day
- Off Topic
- Representative Line
- News Roundup
- Editor's Soapbox
- Software on the Rocks
- Souvenir Potpourri
- Sponsor Post
- Tales from the Interview
- The Daily WTF: Live
- Virtudyne
Admin
VB has nothing to do with it. All the postings about bankers rounding, VB etc etc have completely missed the point. This is a floating point issue, pure and simple.
Admin
And no, 9/10^i -> 0 as i goes to infinity. I really doubt your mathematical abilities.
Admin
In this particular case, why do you need to know where to start multiplying? Obviously, if you wanted to actually write this out by hand completely, you couldn't, but some simple logic can bring you to the answer.
After all, if you were to do this by hand, you'd break down into an infinite series of 3 times 3 for each digit, which is 9. There's no carrying involved, so none of the operations is going to affect any other digit in the result. 3 is also a one-digit number. For 13, you'd have to multiply by 3 and then by 10 and add together, but this isn't necessary for 3. Each individual 3x3 multiplication affects one and only one digit in the result, and a different one each time, so why can't we assume that 0.33333 (repeating) x 3 = 0.99999 (repeating). After all, it doesn't matter if we multiply 3x3 an infinite number of times, does it? It's always going to equal 9.
So, thus, given the following:
We know that 1/3 * 3 = 1, because you multiply the numerators and denominators and then reduce. (1/3 * 3/1 = 3/3 = 1).
But we know that 1/3 = 0.333333 (repeating). You would accept that, right?
Well, if you accept that, then consider the following:
A = 3 B = 1/3 (as a fraction) C = 0.3333333333333 (repeating)
Since B = C, then AB = AC, right? Even though AB = 1 and AC = 0.999999 (repeating)?
So, If 1 != 0.999999 (repeating), then I must have missed something in algebra.
Feel free to repeat the example with 0.1111111 (repeating) x 9 vs. 1/9 x 9.
Admin
If you know how to multiply infinite repeating nubmers, tell me: what's 0.9999~ * 0.999~ is it 2 or 1.9999~ or is it 1.999~99971? (with tilde means repeat). If you multiply infinitely many times will you get 1 or get 0?
Admin
I should said is it 1 or 0.999~ again or 0.9999~~9971.
Admin
[quote user="justme"]I don't really want to argue this any further.
If you know how to multiply infinite repeating nubmers, tell me: what's 0.9999~ * 0.999~ is it 2 or 1.9999~ or is it 1.999~99971? (with tilde means repeat). If you multiply infinitely many times will you get 1 or get 0?[/quote]
I should said is it 1 or 0.999~ again or 0.9999~~9971.[/quote]
I really don't know why this is so difficult to understand. As for multiplying numbers with an infinitely repeating decimal portion, did you note I did say it can't be done by hand? I said you can logically infer the answer in some cases, specifically where the following two conditions are true:
But of course, 0.99~ * 0.99~ = 1, because 1*1 = 1. Since you refuse to accept that 0.99~ = 1 (a fundamental mathematic principle), and I don't feel like educating any further, I'll just cite:
http://www.newton.dep.anl.gov/newton/askasci/1995/math/MATH070.HTM
http://mathforum.org/library/drmath/view/55845.html
lurl]http://polymathematics.typepad.com/polymath/2006/06/no_im_sorry_it_.html[/url]
I'd list even more, but I'm sure you can use Google yourself. If you still refuse to accept this in the face of so much evidence, there's little I can do about it.
Admin
Heximal
Found it hiding in hexadecimal ;~)
Admin
So for everyone that seems to be missing the point on this WTF, here is the answer:
Evidence: I ran this through my favorite language 'Python' to get the same results the author had. I will show just the results of the critcal step:
....looks good....
....oops!
....oh wait!
Solution: (This is the Python equivalent, and it goes in the code right after the line "temp = number * factor") eps = .000001
... but this isn't a really good answer, because you have to hand-hold each time you do any operation on the floating point number. You are better off using a different representation, which is what the original author did.
To summarize, floating point numbers suck if you want values that round out nicely. This is a problem especially with currency because people get bitchy when you lose a cent here or there. Use a string representation, separate dollars and cents as integers, or use a decimal type if possible. For most applications, floating point numbers either don't need to be rounded, or the rounding isn't going to make a major difference. The big lesson here is to never trust a floating point number to be exactly what it reads as when printed with a 'printf'. Don't try to compare a result with the == operator. If you think a value should be an integer, compare it within a range that is very close to the integer you are thinking of. The amount of error possible is known as epsilon, and is defined for the FPU you are using. Keep in mind that the error can compound over multiple operations.
Admin
double x = 95.0 double y = (19.95 - 19.00)* 10.0 * 10.0;
if ( x == y ) { //this fails miserably. }
Admin
The "Round the Round" 24 hour event is a team relay mountain bike race, beginning at noon on Saturday and ending at noon on Sunday. Teams compete for medals, prizes and bragging rights.Anyone who can ride a bike can do this….your team decides how many laps each person does…one or a whole bunch. So bring your camping gear, bike gear and whatever else will keep you going for 24 hours... then come on out and get dirty with us!
real estate
Admin
Here's my version ... which seems to work okay:
Admin
and here is the ref: http://en.wikipedia.org/wiki/Numeral_prefix
Reading that back just makes it sound inappropriate...