Re: BUG #5150: math bug

Поиск
Список
Период
Сортировка
От Robert Haas
Тема Re: BUG #5150: math bug
Дата
Msg-id 603c8f070910302010l5b469ff8v89a2e6e64e74f0de@mail.gmail.com
обсуждение исходный текст
Ответ на BUG #5150: math bug  ("Gray" <gray@ms-irk.ru>)
Ответы Re: BUG #5150: math bug  (Tom Lane <tgl@sss.pgh.pa.us>)
Список pgsql-bugs
On Fri, Oct 30, 2009 at 1:39 AM, Gray <gray@ms-irk.ru> wrote:
>
> The following bug has been logged online:
>
> Bug reference: =A0 =A0 =A05150
> Logged by: =A0 =A0 =A0 =A0 =A0Gray
> Email address: =A0 =A0 =A0gray@ms-irk.ru
> PostgreSQL version: 8.2.6
> Operating system: =A0 i686-pc-linux-gnu
> Description: =A0 =A0 =A0 =A0math bug
> Details:
>
> select 1/3*3,(1.0/3.0)*3.0,floor((1.0/3.0)*3.0);
>
> returns
> 0, 1, 0

Well, the first answer is correct, because 1/3 is a request for
integer division, so you get 0, and 0 * 3 is still zero.

I don't believe the second answer is really what you got, because
surely if you requested floating-point division the answer would be a
floating point number, not just 1.  On pg 8.3.8, I get
0.999999999999999999990, which explains why the third answer comes out
to zero.

In general, floating point arithmetic is inaccurate and sucky.  That
has nothing to do with PostgreSQL; it's just life.

http://en.wikipedia.org/wiki/Floating_point#Accuracy_problems

...Robert

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

Предыдущее
От: Robert Haas
Дата:
Сообщение: Re: BUG #5149: Can't untar the src code file
Следующее
От: "Pierre"
Дата:
Сообщение: BUG #5155: Error compiling postgresql-8.5alpha2