floating point in 2.0

Helen Dawson helend at accessone.com
Wed Jun 6 01:43:50 EDT 2001


Remember that floating point has a mantissa and an *exponent*. So, if I
have a binary floating point format with a one bit mantissa and an eight
bit exponent I can represent numbers like 1 / 2^16, alternately written
as 2^-16. The precise value of this number is:

0.000015258789062500000

and still with that one bit mantissa, giving us less than one decimal
digit of accuracy, we can perfectly represent:

0.000000000931322574615478520000

For numbers of this form (2^-n), the number of decimal digits will be
n. If you strip off the leading zeroes then it will be roughly
n * (1 - base 2 log(10)).

Confusing, but perfectly logical. With the mammoth exponents available
in a 64-bit double it can take literally hundreds of decimal digits to
precisely record the value of a small binary floating point number.

Chris Barker wrote:

> Aahz Maruch wrote:
> > Actually, 2.0 *still* lies:
> >
> > >>> 0.1
> > 0.10000000000000001
> > >>> '%.55f' % 0.1
> > '0.1000000000000000055511151231257827021181583404541015625'
> >
> > It just lies less than it used to.
>
> What the heck are all those digits at the end? Talk about lies, you can
> be sure all those digits aren't being stored (at least not in an IEEE
> 754 64bit double, which stores approx. 16 decimal digits. Approx.
> because it is really a given number of binary digits. I don't have the
> exact number off of the top of my head).
>
> interestingly enough, If you try to diplay more, you get:
> >>> '%.70f' % 0.1
> '0.1000000000000000055511151231257827021181583404541015625000000000000000'
>
> now the extra is all zeros. Also, I get the same 55 digtits, so theya re
> not random garbage. Does anyone know what they are? Perhaps the Intel
> extra precision FPU bits?
>
> -Chris
>
> --
> Christopher Barker,
> Ph.D.
> ChrisHBarker at home.net                 ---           ---           ---
> http://members.home.net/barkerlohmann ---@@       -----@@       -----@@
>                                    ------@@@     ------@@@     ------@@@
> Oil Spill Modeling                ------   @    ------   @   ------   @
> Water Resources Engineering       -------      ---------     --------
> Coastal and Fluvial Hydrodynamics --------------------------------------
> ------------------------------------------------------------------------




More information about the Python-list mailing list