Re: [GENARAL] round() bug

From: Raymond O'Donnell <rod(at)iol(dot)ie>
To: David G Johnston <david(dot)g(dot)johnston(at)gmail(dot)com>, pgsql-general(at)postgresql(dot)org
Subject: Re: [GENARAL] round() bug
Date: 2014-04-15 17:21:01
Message-ID: 534D6A7D.5020106@iol.ie
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On 15/04/2014 17:34, David G Johnston wrote:
> Raymond O'Donnell wrote
>> On 15/04/2014 17:20, David G Johnston wrote:
>>> Willy-Bas Loos-3 wrote
>>>> Hi, I ran into some strange behavior. Seems like a bug to me?
>>>>
>>>> wbloos=# select round(0.5::numeric), round(0.5::double precision);
>>>> round | round -------+------- 1 | 0 (1 row)
>>>
>>> Not a bug; and likely to simple to have escaped notice this long so
>>> the first reaction should be "what am I missing here?"
>>>
>>> [google: round .5 postgresql]
>>>
>>> http://grokbase.com/t/postgresql/pgsql-hackers/03ap11tckn/round-function-wrong/oldest
>>>
>>> Round( numeric ) - 0.5 rounds away from zero Round( float ) -
>>> platform dependent, IEEE 0.5 rounds toward even
>>>
>>> You can argue the decision but at this point it's not likely to
>>> change.
>>
>> Interestingly, I get different results (on both 9.1.4 and 9.3.0) on
>> Windows:
>>
>> postgres=# select round(0.5::numeric), round(0.5::double precision);
>> round | round
>> -------+-------
>> 1 | 1
>> (1 row)
>>
>>
>> postgres=# select version();
>> version
>> -------------------------------------------------------------
>> PostgreSQL 9.1.4, compiled by Visual C++ build 1500, 64-bit
>> (1 row)
>>
>>
>> .... Same on 9.3.0.
>
> 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).

Ray.

--
Raymond O'Donnell :: Galway :: Ireland
rod(at)iol(dot)ie

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message santhosh kumar 2014-04-15 19:34:12 Re: Need some help in postgres locking mechanism
Previous Message David G Johnston 2014-04-15 16:34:14 Re: [GENARAL] round() bug