public inbox for [email protected]  
help / color / mirror / Atom feed
From: Laurenz Albe <[email protected]>
To: [email protected]
To: [email protected]
Subject: Re: Rounding strategy
Date: Thu, 22 Apr 2021 18:54:54 +0200
Message-ID: <[email protected]> (raw)
In-Reply-To: <[email protected]>
References: <[email protected]>
	<[email protected]>

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.

Yours,
Laurenz Albe


Attachments:

  [text/x-patch] 0001-Document-tie-breaking-behavior-of-round.patch (1.2K, 2-0001-Document-tie-breaking-behavior-of-round.patch)
  download | inline diff:
From a0c40fd431820f6d1ce96f5bc3f41bd7665028be Mon Sep 17 00:00:00 2001
From: Laurenz Albe <[email protected]>
Date: Thu, 22 Apr 2021 18:53:14 +0200
Subject: [PATCH] Document tie breaking behavior of round()

---
 doc/src/sgml/func.sgml | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/doc/src/sgml/func.sgml b/doc/src/sgml/func.sgml
index 67d802b02c..fcc09d5231 100644
--- a/doc/src/sgml/func.sgml
+++ b/doc/src/sgml/func.sgml
@@ -1568,7 +1568,9 @@ repeat('Pg', 4) <returnvalue>PgPgPgPg</returnvalue>
         <returnvalue>double precision</returnvalue>
        </para>
        <para>
-        Rounds to nearest integer
+        Rounds to nearest integer.  For <type>numeric</type>, ties are
+        broken by rounding away from 0.  For <type>double precision</type>,
+        the tie breaking behavior is architecture dependent.
        </para>
        <para>
         <literal>round(42.4)</literal>
@@ -1583,7 +1585,7 @@ repeat('Pg', 4) <returnvalue>PgPgPgPg</returnvalue>
        </para>
        <para>
         Rounds <parameter>v</parameter> to <parameter>s</parameter> decimal
-        places
+        places.  Ties are broken by rounding away from 0.
        </para>
        <para>
         <literal>round(42.4382, 2)</literal>
-- 
2.26.3



reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: [email protected]
  Cc: [email protected], [email protected], [email protected]
  Subject: Re: Rounding strategy
  In-Reply-To: <[email protected]>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox