Re: round(x) function

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: "Gaietti, Mauro \(SELEX GALILEO Guest, Italy\)" <mauro(dot)gaietti(at)guests(dot)selexgalileo(dot)com>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: round(x) function
Date: 2010-03-26 17:12:38
Message-ID: 15700.1269623558@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

"Gaietti, Mauro \(SELEX GALILEO Guest, Italy\)" <mauro(dot)gaietti(at)guests(dot)selexgalileo(dot)com> writes:
> This query:
> select round(0.5), round(0.5::integer), round(0.5::bigint), round(
> 0.5::float ), round( 0.5::double precision ),round(cast(0.5 as double
> precision )),round(cast(0.5::double precision as numeric )); has strange
> result:

> 1 1 1 0 0 0 1

> Is this correct?

On most machines the float4/float8 operations follow the IEEE-754 spec's
"round to nearest even" rule for such cases. I think all the other ones
are "add 0.5 and truncate" implementations. It's unlikely we'll mess
with either; and *highly* unlikely that we would change the float
behavior since that's not even under our direct control (the hardware or
libm is what's doing that). There's some case to be made for making
numeric and integer math do it the IEEE way, but I think that would
displease at least as many people as it pleased ...

regards, tom lane

In response to

  • round(x) function at 2010-03-26 16:43:33 from Gaietti, Mauro (SELEX GALILEO Guest, Italy)

Responses

Browse pgsql-general by date

  From Date Subject
Next Message John R Pierce 2010-03-26 17:39:37 Re: Does anyone use in ram postgres database?
Previous Message Merlin Moncure 2010-03-26 16:48:14 Re: Solid State Drives with PG (was: in RAM DB)