Re: Rounding strategy

From: Laurenz Albe <laurenz(dot)albe(at)cybertec(dot)at>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: rudolphfroger(at)dreamsolution(dot)nl, pgsql-docs(at)lists(dot)postgresql(dot)org
Subject: Re: Rounding strategy
Date: 2021-04-23 07:40:04
Message-ID: dbd3c64d0113b4eeeb1330bfa3ca99000c582df4.camel@cybertec.at
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-docs

On Thu, 2021-04-22 at 13:50 -0400, Tom Lane wrote:
> Laurenz Albe <laurenz(dot)albe(at)cybertec(dot)at> writes:
> > On Mon, 2021-04-19 at 08:00 +0000, PG Doc comments form wrote:
> > > The 'round' mathematical function documentation doesn't specify its rounding
> > > strategy. If this would be documented then users can rely on its rounding
> > > behavior. For double precision the rounding probably depends on your
> > > platform. For numeric the function seems to round to nearest with ties going
> > > away from zero (sometimes referred to as "round half up). 6.5 -> 7.0 and
> > > -6.5 -> -7.0.
> >
> > Here is a proposed patch.
>
> LGTM, although I think we can be a bit more specific about the float
> case. I suggest
>
> ... by rounding away from 0. For <type>double precision</type>,
> the tie-breaking behavior is platform dependent, but
> <quote>round to nearest even</quote> is the most common rule.

Makes sense. Here is an updated patch.

Yours,
Laurenz Albe

Attachment Content-Type Size
0001-Document-tie-breaking-behavior-of-round.v2.patch text/x-patch 1.4 KB

In response to

Responses

Browse pgsql-docs by date

  From Date Subject
Next Message Laurenz Albe 2021-04-23 08:51:41 Re: Rounding strategy
Previous Message Justin Pryzby 2021-04-22 23:51:23 Re: INCLUDING COMPRESSION (sort enum fields)