Re: Converting Long to Float: Values not Matching
- From: Joshua Cranmer <Pidgeot18@xxxxxxxxxxxxxxx>
- Date: Thu, 11 Sep 2008 22:47:24 -0400
I am getting:
I tried with multiple numbers but still the values are not equal. What
am I missing?
Floats have limited precision. Your number is larger than the number of the precision.
Internally, numbers are represented as a number (the mantissa) multiplied by some power of 2; your number cannot be exactly represented to the precision that the mantissa has, so it lops off a few bits at the end, giving you a moderately close but not exact approximation.
Beware of bugs in the above code; I have only proved it correct, not tried it. -- Donald E. Knuth