Re: round(x) function

Поиск
Список
Период
Сортировка
От Tom Lane
Тема Re: round(x) function
Дата
Msg-id 15700.1269623558@sss.pgh.pa.us
обсуждение исходный текст
Ответ на round(x) function  ("Gaietti, Mauro \(SELEX GALILEO Guest, Italy\)" <mauro.gaietti@guests.selexgalileo.com>)
Ответы Re: round(x) function  (Justin Graf <justin@magwerks.com>)
Список pgsql-general
"Gaietti, Mauro \(SELEX GALILEO Guest, Italy\)" <mauro.gaietti@guests.selexgalileo.com> writes:
> This query:
> select round(0.5), round(0.5::integer), round(0.5::bigint), round(
> 0.5::float ), round( 0.5::double precision ),round(cast(0.5 as double
> precision )),round(cast(0.5::double precision as numeric )); has strange
> result:

> 1 1 1 0 0 0 1

> Is this correct?

On most machines the float4/float8 operations follow the IEEE-754 spec's
"round to nearest even" rule for such cases.  I think all the other ones
are "add 0.5 and truncate" implementations.  It's unlikely we'll mess
with either; and *highly* unlikely that we would change the float
behavior since that's not even under our direct control (the hardware or
libm is what's doing that).  There's some case to be made for making
numeric and integer math do it the IEEE way, but I think that would
displease at least as many people as it pleased ...

            regards, tom lane

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

Предыдущее
От: "Gaietti, Mauro \(SELEX GALILEO Guest, Italy\)"
Дата:
Сообщение: round(x) function
Следующее
От: John R Pierce
Дата:
Сообщение: Re: Does anyone use in ram postgres database?