Re: [HACKERS] 123.45 - 123 = 0.45
Bruce Momjian <maillist@candle.pha.pa.us>
From: Bruce Momjian <maillist@candle.pha.pa.us>
To: daveh@insightdist.com (David Hartwig)
Cc: sferac@bo.nettuno.it, pgsql-hackers@postgreSQL.org
Date: 1998-12-15T16:20:15Z
Lists: 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, Pennsylvania 19026