Re: Rounding to even for numeric data type

From: Michael Paquier <michael(dot)paquier(at)gmail(dot)com>
To: James Cloos <cloos(at)jhcloos(dot)com>
Cc: PostgreSQL mailing lists <pgsql-hackers(at)postgresql(dot)org>, Gavin Flower <GavinFlower(at)archidevsys(dot)co(dot)nz>, Dean Rasheed <dean(dot)a(dot)rasheed(at)gmail(dot)com>, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Subject: Re: Rounding to even for numeric data type
Date: 2015-03-30 00:35:09
Message-ID: CAB7nPqQ4pPkE8aDsKg5Kzty2o_xHH5URADJBC1twG_1--cRntw@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Mon, Mar 30, 2015 at 4:51 AM, James Cloos <cloos(at)jhcloos(dot)com> wrote:
>>>>>> "MP" == Michael Paquier <michael(dot)paquier(at)gmail(dot)com> writes:
>
> MP> So, attached is a patch that does 1) and 2) to make clear to the
> MP> user how numeric and double precision behave regarding rounding.
> MP> I am adding it to CF 2015-06 to keep track of it...
>
> Given that the examples show -2.5 rounds to -3, the IEEE term is
> roundTiesToAway, and the typical conversational english is round ties
> away from zero.

Ah, thanks for the correct wording. Fixed in the attached.

> RoundUp means mean towards +Infinity.
>
> 754 specifies that for decimal, either roundTiesToEven or roundTiesToAway
> are acceptable defaults, and which of the two applies is language dependent.
> Does ANSI SQL say anything about how numeric should round?
>
> In general, for decimals (or anything other than binary), there are
> twelve possible roundings:
>
> ToEven ToOdd AwayFromZero ToZero Up Down
> TiesToEven TiesToOdd TiesAwayFromZero TiesToZero TiesUp TiesDown
>
> (Up is the same as ceil(3), Down as floor(3).)

Well, I am not sure about that... But reading this thread changing the
default rounding sounds unwelcome. So it may be better to just put in
words the rounding method used now in the docs, with perhaps a mention
that this is not completely in-line with the SQL spec if that's not
the case.
--
Michael

Attachment Content-Type Size
0001-Precise-rounding-behavior-of-numeric-and-double-prec.patch application/x-patch 8.3 KB

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Andres Freund 2015-03-30 00:47:09 Re: Relation extension scalability
Previous Message Robert Haas 2015-03-30 00:02:06 Re: Relation extension scalability