Re: Bug #644: Incorrect result in math operation

From: Dmitry Tsitelov <cit(at)tag-ltd(dot)spb(dot)ru>
To: franblay(at)ono(dot)com, pgsql-bugs(at)postgresql(dot)org
Subject: Re: Bug #644: Incorrect result in math operation
Date: 2002-04-24 09:17:25
Message-ID: 20020424131725.1fecf713.cit@tag-ltd.spb.ru
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

Hi!

On Wed, 24 Apr 2002 04:33:00 -0400 (EDT)
pgsql-bugs(at)postgresql(dot)org wrote:

> Francisco Blay (franblay(at)ono(dot)com) reports a bug with a severity of 3
> The lower the number the more severe it is.
>
> Short Description
> Incorrect result in math operation
>
> Long Description
> 3088.8 - (2847.64 + 241.16)=4.54747350886464e-13
> It's spected to be 0.0 the result of this operation (I think)
> Got the same results in
>
...
> datadb=# select 3088.8 - (2847.64 + 241.16) AS silly;
> silly
> ----------------------
> 4.54747350886464e-13
> (1 row)
>

I think it's a limitation of floating point numbers representation, not a PostgreSQL bug. Use NUMERIC type, if you need an "exact" precision:

org=> SELECT 3088.8::numeric(8,3) - (2847.64::numeric(8,3) + 241.16::numeric(8,3)) AS silly;
silly
-------
0.000
(1 row)

Best regards

--
Dmitry Tsitelov
mailto:cit(at)tag-ltd(dot)spb(dot)ru

In response to

Browse pgsql-bugs by date

  From Date Subject
Next Message Hubert depesz Lubaczewski 2002-04-24 11:17:22 problems with non-trust authentication methods in 7.3devel?
Previous Message pgsql-bugs 2002-04-24 08:33:00 Bug #644: Incorrect result in math operation