| From: | Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> |
|---|---|
| To: | "mirek" <mirek(at)mascort(dot)com(dot)pl> |
| Cc: | pgsql-bugs(at)postgresql(dot)org |
| Subject: | Re: BUG #3991: pgsql function sum() |
| Date: | 2008-02-26 15:45:08 |
| Message-ID: | 2945.1204040708@sss.pgh.pa.us |
| Views: | Whole Thread | Raw Message | Download mbox | Resend email |
| Thread: | |
| Lists: | pgsql-bugs |
"mirek" <mirek(at)mascort(dot)com(dot)pl> writes:
> problem is in: sum(wvat-wvatp) where field in view wvat = 33.08 and wvatp =
> 36.09
> Result is -3.01000000000001
> If I ask postgres manualy: select sum(33.08 - 36.09)
> result is ok -3.01
> Now I fix it with round function but i think that is a bug.
You evidently haven't got much experience with working with
floating-point arithmetic.
regression=# select 33.08::numeric - 36.09::numeric;
?column?
----------
-3.01
(1 row)
regression=# select 33.08::float8 - 36.09::float8;
?column?
-------------------
-3.01000000000001
(1 row)
This is not a bug, it's an inherent consequence of the fact that these
decimal values are not exactly represented in a binary floating-point
system. If you don't like it, don't use float.
regards, tom lane
| From | Date | Subject | |
|---|---|---|---|
| Next Message | Zdenek Kotala | 2008-02-26 15:51:07 | Re: BUG #3991: pgsql function sum() |
| Previous Message | Zdenek Kotala | 2008-02-26 12:55:19 | Re: BUG #3991: pgsql function sum() |