Re: Unexpected result using floor() function

From: Adrian Klaver <adrian(dot)klaver(at)aklaver(dot)com>
To: Pujol Mathieu <mathieu(dot)pujol(at)realfusio(dot)com>, pgsql-general(at)postgresql(dot)org
Subject: Re: Unexpected result using floor() function
Date: 2016-03-14 14:29:28
Message-ID: 56E6CAC8.90300@aklaver.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On 03/14/2016 07:21 AM, Pujol Mathieu wrote:
> Hi
> I reproduce your bug using "PostgreSQL 9.3.6, compiled by Visual C++
> build 1600, 64-bit" on Windows 8
> I also notice that SELECT floor(4.725 * power(10, 2)::numeric + 0.5)
> work as expected

Seems to be related to the two forms of power():

http://www.postgresql.org/docs/9.4/interactive/functions-math.html

Function Return Type
power(a dp, b dp) dp
power(a numeric, b numeric) numeric

So just doing:

test=> select floor(4.725 * power(10, 2.0) + 0.5);
floor
-------
473
(1 row)

works.

>
> Mathieu
>
> Le 14/03/2016 15:11, Frank Millman a écrit :
>> Hi all
>> I am running PostgreSQL 9.4.4 on Fedora 22.
>> SELECT floor(4.725 * 100 + 0.5) returns 473, which is what I expected.
>> SELECT floor(4.725 * power(10, 2) + 0.5) returns 472, which I find
>> surprising.
>> Please can someone explain the anomaly.
>> Thanks
>> Frank Millman
>
> --
> Mathieu PUJOL
> Ingénieur Réalité Virtuelle
> Tel : 05.81.33.13.36
> REAL FUSIO - 3D Computer Graphics
> 9, rue Paul Mesple - 31100 TOULOUSE - FRANCE
> mathieu(dot)pujol(at)realfusio(dot)com -http://www.realfusio.com
>

--
Adrian Klaver
adrian(dot)klaver(at)aklaver(dot)com

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Merlin Moncure 2016-03-14 14:32:07 Re: Unexpected result using floor() function
Previous Message Merlin Moncure 2016-03-14 14:29:07 Re: Unexpected result using floor() function