Re: [GENARAL] round() bug

Поиск
Список
Период
Сортировка
От Albe Laurenz
Тема Re: [GENARAL] round() bug
Дата
Msg-id A737B7A37273E048B164557ADEF4A58B17CF0DB3@ntex2010i.host.magwien.gv.at
обсуждение исходный текст
Ответ на Re: [GENARAL] round() bug  (Raymond O'Donnell <rod@iol.ie>)
Список pgsql-general
Raymond O'Donnell wrote:
>>> Interestingly, I get different results (on both 9.1.4 and 9.3.0) on
>>> Windows:

>> I'm not particularly surprised that Windows is not being IEEE compliant, and
>> instead chooses the more common round-away-from-zero behavior, here though I
>> am unsure where the dependent implementation would end up existing.

> Oh, so does the rounding code use OS facilities, then, rather than being
> implemented in Postgres? - Didn't know that, though I was aware PG does
> that in other areas (collation, for example).

Yes.

But this here:
http://msdn.microsoft.com/en-us/library/0b34tf65.aspx
claims that Windows C++ is IEEE compliant, so it should behave like Linux.

On systems where the function exists, PostgreSQL uses the rint() function.
On other systems (like Windows), it defines rint() as

double
rint(double x)
{
    return (x >= 0.0) ? floor(x + 0.5) : ceil(x - 0.5);
}

It is interesting that the above function, when applied to 0.5 on my
Linux x86_64 system, yields "1".

So while rint() follows the IEEE standard's default (if a value is exactly
between two integers, round to the even one), PostgreSQL's replacement
function doesn't.

So maybe there is a bug after all, and the replacement function
should be changed.

Yours,
Laurenz Albe

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

Предыдущее
От: Dev Kumkar
Дата:
Сообщение: Heartbleed Impact
Следующее
От: Albe Laurenz
Дата:
Сообщение: Re: Heartbleed Impact