floating point in 2.0

Chris Barker chrishbarker at home.net
Thu Jun 7 14:54:43 EDT 2001


Aahz Maruch wrote:
> >> >>> 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).
> 
> It's 52 binary bits.  The decimal 0.1 is converted to the nearest
> approximation using all 52 bits.  The number you see above is the
> precise conversion of that approximation back to decimal.  So yes, all
> of those digits are being stored.  Note carefully that 754 doesn't store
> *any* decimal digits, it only stores binary digits.  What you meant is
> that up to 16 decimal digits of precision can be *converted* to 52 binary
> digits with "reasonable" accuracy.  Because decimal contains a power of
> two in its base, the reverse conversion *can* be made precisely.
> 
> (Did I get it right this time, Uncle Timmy?)

I'm pretty sure that a 52 binary bit mantissa will never create 52
decimal digits of accuracy. YOu can only get about 17 digits. However, I
forgot that pesky exponent, as Helen Dawson so kindly pointed out. IN
fact, here example with a 1 bit mantissa resulting in a decimal
representation with a whole lot of accurate digits makes the point: the
number of digits in one base has no default direct coorespondace to the
number of digits in another base. I should have know this from the
reverse case that this whole discussion started with:

1 / 10 takes only one digit to represent accurately in base ten but
takes as many bits as you have to not precisly represent in binary. A
similar situation can be true in the reverse direction.

Python's display of 50 decimal digits is essentially arbitrary, not a
function of the 52 bits that are used to store a Float (on my machine).
>From the library reference, see my previous post

-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