Re: BUG in postgres mathematic - Mailing list pgsql-bugs

From Robert B. Easter
Subject Re: BUG in postgres mathematic
Date
Msg-id 0101260412020Q.08820@comptechnews
Whole thread Raw
In response to Re: BUG in postgres mathematic  (Tom Lane <tgl@sss.pgh.pa.us>)
List pgsql-bugs
Notice how the INT4 rounding is banker's rounding (round to the nearest even
number).  That is what we would want the INT8 to do as well, not just a
simple round like I mentioned before. Again, the INT8 shows truncation.  I've
been looking around the source code, but I can't see where all this
happens.

reaster=# SELECT 1.5::FLOAT::INT4;
 ?column?
----------
        2
(1 row)

reaster=# SELECT 2.5::FLOAT::INT4;
 ?column?
----------
        2
(1 row)

reaster=# SELECT 1.5::FLOAT::INT8;
 ?column?
----------
        1
(1 row)

reaster=# SELECT 2.5::FLOAT::INT8;
 ?column?
----------
        2
(1 row)


On Thursday 25 January 2001 22:52, Tom Lane wrote:
> "Robert B. Easter" <reaster@comptechnews.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

--
-------- Robert B. Easter  reaster@comptechnews.com ---------
-- CompTechNews Message Board http://www.comptechnews.com/ --
-- CompTechServ Tech Services http://www.comptechserv.com/ --
---------- http://www.comptechnews.com/~reaster/ ------------

pgsql-bugs by date:

Previous
From: "Michael Richards"
Date:
Subject: Re: Postgres int rounding
Next
From: Peter T Mount
Date:
Subject: Re: Re: [INTERFACES] jdbc driver: Support for 'BOOL'