Re: [GENARAL] round() bug

From: Albe Laurenz <laurenz(dot)albe(at)wien(dot)gv(dot)at>
To: "rod(at)iol(dot)ie" <rod(at)iol(dot)ie>, David G Johnston <david(dot)g(dot)johnston(at)gmail(dot)com>, "pgsql-general(at)postgresql(dot)org" <pgsql-general(at)postgresql(dot)org>
Subject: Re: [GENARAL] round() bug
Date: 2014-04-16 09:43:22
Message-ID: A737B7A37273E048B164557ADEF4A58B17CF0DB3@ntex2010i.host.magwien.gv.at
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Albe Laurenz 2014-04-16 09:48:23 Re: Heartbleed Impact
Previous Message Dev Kumkar 2014-04-16 08:48:04 Heartbleed Impact