Re: [HACKERS] 123.45 - 123 = 0.45

Поиск
Список
Период
Сортировка
От Bruce Momjian
Тема Re: [HACKERS] 123.45 - 123 = 0.45
Дата
Msg-id 199812151620.LAA16225@candle.pha.pa.us
обсуждение исходный текст
Ответ на Re: [HACKERS] 123.45 - 123 = 0.45  (David Hartwig <daveh@insightdist.com>)
Список 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 по дате отправления:

Предыдущее
От: Sferacarta Software
Дата:
Сообщение: Re[2]: [HACKERS] 123.45 - 123 = 0.45
Следующее
От: "Jackson, DeJuan"
Дата:
Сообщение: RE: [HACKERS] 123.45 - 123 = 0.45