Re: [HACKERS] 123.45 - 123 = 0.45

Поиск
Список
Период
Сортировка
От Tom Lane
Тема Re: [HACKERS] 123.45 - 123 = 0.45
Дата
Msg-id 26456.913767675@sss.pgh.pa.us
обсуждение исходный текст
Ответ на RE: [HACKERS] 123.45 - 123 = 0.45  ("Jackson, DeJuan" <djackson@cpsgroup.com>)
Ответы Re: [HACKERS] 123.45 - 123 = 0.45  (Bruce Momjian <maillist@candle.pha.pa.us>)
Список pgsql-hackers
"Jackson, DeJuan" <djackson@cpsgroup.com> writes:
> But, the problem is that it is irrational in base 2 (or at least so many
> digits that it won't fit).

It's not irrational in any base.  123.45 = 12345/100 is a ratio of
integers, ie, rational.  The problem is that the exact representation
of this number as a base-2 fraction is longer than the 52 or so bits
available in float8 format.  (I think it's an infinite repeating
fraction, in the same way that 1/9 = 0.111111111111111111111111111...
is a repeating fraction in base 10.  But even a terminating fraction
will get rounded off as a float8 if it takes more than 52 bits.)

Irrational numbers are those which are not expressible as the ratio of
any two integers, eg, square root of 2.  (The ancient Greeks became
*very* unhappy when they realized that there were such things.)  A
subcategory is transcendentals, which are not expressible as the
solution of any algebraic equation, eg, pi.

Rational numbers have either terminating or repeating expansions in
any base you care to use; irrationals never do.

Sorry, I'll get off my math-pedant soapbox now.  Just tend to get
annoyed when people misuse technical terms.
        regards, tom lane


В списке pgsql-hackers по дате отправления:

Предыдущее
От: Clark Evans
Дата:
Сообщение: ...
Следующее
От: Bruce Momjian
Дата:
Сообщение: Re: [HACKERS] 123.45 - 123 = 0.45