Re: Different printed output with floating point numbers

From: Russell Browne (russ_at_amc.com)
Date: Wed Mar 07 2001 - 18:10:31 GMT


As William Dowling points out:

> "1.3" and "1.29999995232" are two ASCII decimal representations of the
> same underlying 32-bit binary floating point value, that differ only
> in how much they are lying about the precision (32 bits) of the
> underlying value. (There are infinitely many such ASCII decimal
> representationas -- add as many mor 9's as you like.)

In fact, if you try the following program:

  
   int main()
   {
       float foo = 1.3;
       double food = foo;
       return 0;
   }

Run under ups, stop on the return and display foo and food, you see 

      main                                           bob.c:5
	       float <foo>                        1.3
	       double <food>                      1.29999995232

The problem Bob reports arises in the C interpreter, where there is a
conversion of intermediate float results to doubles.

Russ


This archive was generated by hypermail 2.1.4 : Wed Feb 13 2002 - 21:51:33 GMT