#29736 - _pluto9 - Wed Nov 24, 2004 4:59 pm
Last night I was making a program in MSVC 6 to convert a number into scientific notation, I wrote the part for numbers where the exponent was positive first which worked fine, then I wrote the part that handes negative exponients, for some reason, I got the following output:
(.01) = 1 x 10 ^ 2
(.001) = 10 x 10 ^ 2 <-- the error!!!
(.0001) = 1 x 10 ^ 4
(.00001) = 1 x 10 ^ 5
(.000001) = 1 x 10 ^ 6
etc..
now the code I was using looked like this (n is the original number):
I isolated the error, and found that it wasn't getting the third loop (where d would be 1000.0f, and e would be -3), because (0.001 * 100.0f) <= 0.1 was returning false .... ?!@#!@$!
I could figure for the life of me, why it was doing that, so I changed all my floats to doubles, and the problem disapeared.
Is this an issue with floats in general? or is it a bug in MSVC 6?
(.01) = 1 x 10 ^ 2
(.001) = 10 x 10 ^ 2 <-- the error!!!
(.0001) = 1 x 10 ^ 4
(.00001) = 1 x 10 ^ 5
(.000001) = 1 x 10 ^ 6
etc..
now the code I was using looked like this (n is the original number):
Code: |
for(e=-1, d=10.0f; abs(n)*d <= 0.1f; e--, d*=10.0f); |
I isolated the error, and found that it wasn't getting the third loop (where d would be 1000.0f, and e would be -3), because (0.001 * 100.0f) <= 0.1 was returning false .... ?!@#!@$!
I could figure for the life of me, why it was doing that, so I changed all my floats to doubles, and the problem disapeared.
Is this an issue with floats in general? or is it a bug in MSVC 6?