Re: [GENARAL] round() bug - Mailing list pgsql-general

From Albe Laurenz
Subject Re: [GENARAL] round() bug
Date
Msg-id A737B7A37273E048B164557ADEF4A58B17CF0DB3@ntex2010i.host.magwien.gv.at
Whole thread Raw
In response to Re: [GENARAL] round() bug  (Raymond O'Donnell <rod@iol.ie>)
List 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 by date:

Previous
From: Dev Kumkar
Date:
Subject: Heartbleed Impact
Next
From: Albe Laurenz
Date:
Subject: Re: Heartbleed Impact