Thread: Re: Postgres int rounding

Re: Postgres int rounding

From
"Michael Richards"
Date:
Is postgres going to use the scientific method of rounding or just
the simple one? Or even make it configurable. As I recall, the
scientific method says that 4.5 should be rounded to 4 and 5.5 should
be rounded to 6. The idea was that even numbers were easier to work
with and rounding all the x.5 numbers up as the common method says
will eventually skew your average. Rounding evens down and odds up
would probably generate a number of bug reports from people who are
not aware of this though...

-Michael

> 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.

_________________________________________________________________
     http://fastmail.ca/ - Fast Free Web Email for Canadians

Re: Re: Postgres int rounding

From
Bruce Momjian
Date:
> Is postgres going to use the scientific method of rounding or just
> the simple one? Or even make it configurable. As I recall, the
> scientific method says that 4.5 should be rounded to 4 and 5.5 should
> be rounded to 6. The idea was that even numbers were easier to work
> with and rounding all the x.5 numbers up as the common method says
> will eventually skew your average. Rounding evens down and odds up
> would probably generate a number of bug reports from people who are
> not aware of this though...


I think some standard required the even/odd rounding behavour.

>
> -Michael
>
> > 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.
>
> _________________________________________________________________
>      http://fastmail.ca/ - Fast Free Web Email for Canadians
>


--
  Bruce Momjian                        |  http://candle.pha.pa.us
  pgman@candle.pha.pa.us               |  (610) 853-3000
  +  If your life is a hard drive,     |  830 Blythe Avenue
  +  Christ can be your backup.        |  Drexel Hill, Pennsylvania 19026