From: | "Robert B(dot) Easter" <reaster(at)comptechnews(dot)com> |
---|---|
To: | Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> |
Cc: | Max Vaschenko <max(at)nino(dot)ru>, pgsql-bugs(at)postgresql(dot)org |
Subject: | Re: BUG in postgres mathematic |
Date: | 2001-01-26 05:49:46 |
Message-ID: | 0101260049460N.08820@comptechnews |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-bugs |
On Thursday 25 January 2001 22:52, Tom Lane wrote:
> "Robert B. Easter" <reaster(at)comptechnews(dot)com> writes:
> > This problem is not specific to Postgres.
>
> The fact that 5*27.81*100 != 27.81*100*5 is certainly a garden-variety
> floating-point roundoff error. However, I think Max has a fair
> complaint here: it seems float-to-int8 conversion is truncating, not
> rounding like the other conversions to integer do.
>
> regression=# select 4.7::float8::int4;
> ?column?
> ----------
> 5
> (1 row)
>
> regression=# select 4.7::float8::int8;
> ?column?
> ----------
> 4
> (1 row)
>
> Seems to me this is a bug we should fix.
>
> regards, tom lane
Yeah, I agree. It isn't right that it truncates and that is something C does
appearently. The fix is to pass the float through a rounding something like
(long)(f + 0.5) or else C just truncates it off. This must already be
happening for the int4 conversion or C would do the same thing to it. I
didn't look at the Postgres sources yet, but it is probably one of those very
easy things to fix. :)
--
-------- Robert B. Easter reaster(at)comptechnews(dot)com ---------
-- CompTechNews Message Board http://www.comptechnews.com/ --
-- CompTechServ Tech Services http://www.comptechserv.com/ --
---------- http://www.comptechnews.com/~reaster/ ------------
From | Date | Subject | |
---|---|---|---|
Next Message | Alex Krohn | 2001-01-26 05:51:37 | Re: select fails on indexed varchars. |
Previous Message | Tom Lane | 2001-01-26 05:15:18 | Re: select fails on indexed varchars. |