Re: [HACKERS] 123.45 - 123 = 0.45 - Mailing list pgsql-hackers

From Bruce Momjian
Subject Re: [HACKERS] 123.45 - 123 = 0.45
Date
Msg-id 199812151620.LAA16225@candle.pha.pa.us
Whole thread Raw
In response to Re: [HACKERS] 123.45 - 123 = 0.45  (David Hartwig <daveh@insightdist.com>)
List pgsql-hackers
> Try this:
> 
> #include <stdio.h>
> 
> main()
> {
> double f1 = 123.45;
> double f2 = 123.00;
> double r;
> 
>     r = f1 - f2;
>     printf("%0.15f  %0.15f  %0.15f\n", f1, f2, r);
> }
> 
> Internal representation of 123.45 is not exact.   In the conversion to
> binary, an irrational number is created which is truncated to 64 bits.

Yes, someone pointed this out to me in private e-mail, and I wrote a C
program to confirm it.  I just had never seen such rounding on such
small non-irrational numbers.

--  Bruce Momjian                        |  http://www.op.net/~candle maillist@candle.pha.pa.us            |  (610)
853-3000+  If your life is a hard drive,     |  830 Blythe Avenue +  Christ can be your backup.        |  Drexel Hill,
Pennsylvania19026
 


pgsql-hackers by date:

Previous
From: Sferacarta Software
Date:
Subject: Re[2]: [HACKERS] 123.45 - 123 = 0.45
Next
From: "Jackson, DeJuan"
Date:
Subject: RE: [HACKERS] 123.45 - 123 = 0.45