Re: round(50.5) = 50

From: Stephan Szabo <sszabo(at)megazone(dot)bigpanda(dot)com>
To: Philipp Matthias Hahn <Philipp(dot)Hahn(at)informatik(dot)uni-oldenburg(dot)de>
Cc: Peter Eisentraut <peter_e(at)gmx(dot)net>, pgsql-bugs(at)postgresql(dot)org
Subject: Re: round(50.5) = 50
Date: 2004-03-06 04:24:20
Message-ID: 20040305202025.Q3190@megazone.bigpanda.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs


On Mon, 1 Mar 2004, Philipp Matthias Hahn wrote:

> Peter Eisentraut wrote:
> > Philipp Matthias Hahn wrote:
> >
> >># SELECT round(5.5::float4),round(50.5::float4);
> >> round | round
> >>-------+-------
> >> 6 | 50
> >>(1 row)
> >>
> >>I think this is a bug, since I would expect 6 and 51.
> >
> > The default rounding mode for floating point (determined by your C
> > library, mostly) it to round toward the closest even number.
>
> No, see program and its results below.

Postgresql uses rint/rintf to do the rounding not round/roundf so you're
comparing apples and oranges (specifically round/roundf explicitly do not
honor the rounding direction)

----
>From my system man pages:

double rint(double x);
float rintf(float x);
long double rintl(long double x);

DESCRIPTION

The nearbyint functions round their argument to an integer value in
floating point format, using the current rounding direction and without
raising the inexact exception.

The rint functions do the same, but will raise the inexact exception when
the result differs in value from the argument.

double round(double x);
float roundf(float x);
long double roundl(long double x);

DESCRIPTION

These functions round x to the nearest integer, but round halfway cases
away from zero (regardless of the current rounding direction), instead of
to the nearest even integer like rint().

In response to

Browse pgsql-bugs by date

  From Date Subject
Next Message Pierre Marie OUM SACK 2004-03-06 12:28:51 postmaster ?????
Previous Message Tom Lane 2004-03-05 21:11:28 Re: New Instance of Variable Not Found in Subplan Bug