Re: round(50.5) = 50

Поиск
Список
Период
Сортировка
От Stephan Szabo
Тема Re: round(50.5) = 50
Дата
Msg-id 20040305202025.Q3190@megazone.bigpanda.com
обсуждение исходный текст
Ответ на Re: round(50.5) = 50  (Philipp Matthias Hahn <Philipp.Hahn@informatik.uni-oldenburg.de>)
Список 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().

В списке pgsql-bugs по дате отправления:

Предыдущее
От: margitsw@t-online.de (Margit Schubert-While)
Дата:
Сообщение: Re: ecpg segmentation error
Следующее
От: Enrico Weigelt
Дата:
Сообщение: buglet in 7.1.4