floating point in 2.0

Tim Peters tim.one at home.com
Tue Jun 5 20:20:48 EDT 2001


[Aahz]
> Actually, 2.0 *still* lies:
>
> >>> 0.1
> 0.10000000000000001
> >>> '%.55f' % 0.1
> '0.1000000000000000055511151231257827021181583404541015625'
>
> It just lies less than it used to.

Note that this is platform-dependent, and even across platforms that conform
fully to IEEE-754:  they're allowed to display only zeroes after the 17th
significant decimal digit.

[Chris Barker]
> 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).

A 754 double has 53 bits.  You're familiar with base 2, so this should be
easy:

1/2**1 = 0.5
1/2**2 = 0.25
1/2**3 = 0.125
1/2**4 = 0.0625
1/2**5 = 0.03125

and so on, until

1/2**53 = 0.00000000000000011102230246251565404236316680908203125

Now what do you think the exact decimal value of the exact IEEE double 1/2 +
1/2**53 is?

rhetorical-question-no-answer-required<wink>-ly y'rs  - tim





More information about the Python-list mailing list