pg.ddx.io pgsql-docs@postgresql.org mailing list archive
help / color / mirror / Atom feedRounding strategy
7+ messages / 4 participants
[nested] [flat]
* Rounding strategy
@ 2021-04-19 08:00 PG Doc comments form <noreply@postgresql.org>
2021-04-19 15:37 ` Re: Rounding strategy Laurenz Albe <laurenz.albe@cybertec.at>
0 siblings, 1 reply; 7+ messages in thread
From: PG Doc comments form @ 2021-04-19 08:00 UTC (permalink / raw)
To: pgsql-docs@lists.postgresql.org; +Cc: rudolphfroger@dreamsolution.nl
The following documentation comment has been logged on the website:
Page: https://www.postgresql.org/docs/13/functions-math.html
Description:
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.
^ permalink raw reply [nested|flat] 7+ messages in thread
* Re: Rounding strategy
2021-04-19 08:00 Rounding strategy PG Doc comments form <noreply@postgresql.org>
@ 2021-04-19 15:37 ` Laurenz Albe <laurenz.albe@cybertec.at>
2021-04-22 16:54 ` Re: Rounding strategy Laurenz Albe <laurenz.albe@cybertec.at>
0 siblings, 1 reply; 7+ messages in thread
From: Laurenz Albe @ 2021-04-19 15:37 UTC (permalink / raw)
To: rudolphfroger@dreamsolution.nl; pgsql-docs@lists.postgresql.org
On Mon, 2021-04-19 at 08:00 +0000, PG Doc comments form wrote:
> The following documentation comment has been logged on the website:
>
> Page: https://www.postgresql.org/docs/13/functions-math.html
> Description:
>
> 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.
+1
Yours,
Laurenz Albe
^ permalink raw reply [nested|flat] 7+ messages in thread
* Re: Rounding strategy
2021-04-19 08:00 Rounding strategy PG Doc comments form <noreply@postgresql.org>
2021-04-19 15:37 ` Re: Rounding strategy Laurenz Albe <laurenz.albe@cybertec.at>
@ 2021-04-22 16:54 ` Laurenz Albe <laurenz.albe@cybertec.at>
2021-04-22 17:50 ` Re: Rounding strategy Tom Lane <tgl@sss.pgh.pa.us>
0 siblings, 1 reply; 7+ messages in thread
From: Laurenz Albe @ 2021-04-22 16:54 UTC (permalink / raw)
To: rudolphfroger@dreamsolution.nl; pgsql-docs@lists.postgresql.org
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.3K, ../../bc1b85d65c284e3aaa718eba5f43dd4b970ccf33.camel@cybertec.at/2-0001-Document-tie-breaking-behavior-of-round.patch)
download | inline diff:
From a0c40fd431820f6d1ce96f5bc3f41bd7665028be Mon Sep 17 00:00:00 2001
From: Laurenz Albe <laurenz.albe@cybertec.at>
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
^ permalink raw reply [nested|flat] 7+ messages in thread
* Re: Rounding strategy
2021-04-19 08:00 Rounding strategy PG Doc comments form <noreply@postgresql.org>
2021-04-19 15:37 ` Re: Rounding strategy Laurenz Albe <laurenz.albe@cybertec.at>
2021-04-22 16:54 ` Re: Rounding strategy Laurenz Albe <laurenz.albe@cybertec.at>
@ 2021-04-22 17:50 ` Tom Lane <tgl@sss.pgh.pa.us>
2021-04-23 07:40 ` Re: Rounding strategy Laurenz Albe <laurenz.albe@cybertec.at>
0 siblings, 1 reply; 7+ messages in thread
From: Tom Lane @ 2021-04-22 17:50 UTC (permalink / raw)
To: Laurenz Albe <laurenz.albe@cybertec.at>; +Cc: rudolphfroger@dreamsolution.nl; pgsql-docs@lists.postgresql.org
Laurenz Albe <laurenz.albe@cybertec.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.
regards, tom lane
^ permalink raw reply [nested|flat] 7+ messages in thread
* Re: Rounding strategy
2021-04-19 08:00 Rounding strategy PG Doc comments form <noreply@postgresql.org>
2021-04-19 15:37 ` Re: Rounding strategy Laurenz Albe <laurenz.albe@cybertec.at>
2021-04-22 16:54 ` Re: Rounding strategy Laurenz Albe <laurenz.albe@cybertec.at>
2021-04-22 17:50 ` Re: Rounding strategy Tom Lane <tgl@sss.pgh.pa.us>
@ 2021-04-23 07:40 ` Laurenz Albe <laurenz.albe@cybertec.at>
2021-04-23 08:51 ` Re: Rounding strategy Laurenz Albe <laurenz.albe@cybertec.at>
0 siblings, 1 reply; 7+ messages in thread
From: Laurenz Albe @ 2021-04-23 07:40 UTC (permalink / raw)
To: Tom Lane <tgl@sss.pgh.pa.us>; +Cc: rudolphfroger@dreamsolution.nl; pgsql-docs@lists.postgresql.org
On Thu, 2021-04-22 at 13:50 -0400, Tom Lane wrote:
> Laurenz Albe <laurenz.albe@cybertec.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
Attachments:
[text/x-patch] 0001-Document-tie-breaking-behavior-of-round.v2.patch (1.4K, ../../dbd3c64d0113b4eeeb1330bfa3ca99000c582df4.camel@cybertec.at/2-0001-Document-tie-breaking-behavior-of-round.v2.patch)
download | inline diff:
From 7881d8a73f6cf93c21a9d1405736c6ce6cff5429 Mon Sep 17 00:00:00 2001
From: Laurenz Albe <laurenz.albe@cybertec.at>
Date: Fri, 23 Apr 2021 09:38:27 +0200
Subject: [PATCH] Document tie breaking behavior of round()
---
doc/src/sgml/func.sgml | 8 ++++++--
1 file changed, 6 insertions(+), 2 deletions(-)
diff --git a/doc/src/sgml/func.sgml b/doc/src/sgml/func.sgml
index 67d802b02c..9ed39dabfd 100644
--- a/doc/src/sgml/func.sgml
+++ b/doc/src/sgml/func.sgml
@@ -1568,7 +1568,11 @@ 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, but
+ <quote>round to nearest even</quote> in accordance with IEEE-754
+ is the most common rule.
</para>
<para>
<literal>round(42.4)</literal>
@@ -1583,7 +1587,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
^ permalink raw reply [nested|flat] 7+ messages in thread
* Re: Rounding strategy
2021-04-19 08:00 Rounding strategy PG Doc comments form <noreply@postgresql.org>
2021-04-19 15:37 ` Re: Rounding strategy Laurenz Albe <laurenz.albe@cybertec.at>
2021-04-22 16:54 ` Re: Rounding strategy Laurenz Albe <laurenz.albe@cybertec.at>
2021-04-22 17:50 ` Re: Rounding strategy Tom Lane <tgl@sss.pgh.pa.us>
2021-04-23 07:40 ` Re: Rounding strategy Laurenz Albe <laurenz.albe@cybertec.at>
@ 2021-04-23 08:51 ` Laurenz Albe <laurenz.albe@cybertec.at>
2021-04-23 16:15 ` Re: Rounding strategy rudolphfroger@dreamsolution.nl
0 siblings, 1 reply; 7+ messages in thread
From: Laurenz Albe @ 2021-04-23 08:51 UTC (permalink / raw)
To: Tom Lane <tgl@sss.pgh.pa.us>; +Cc: rudolphfroger@dreamsolution.nl; pgsql-docs@lists.postgresql.org
On Fri, 2021-04-23 at 09:40 +0200, Laurenz Albe wrote:
> Makes sense. Here is an updated patch.
I see that you have already committed your proposed version.
Thanks!
Yours,
Laurenz Albe
^ permalink raw reply [nested|flat] 7+ messages in thread
* Re: Rounding strategy
2021-04-19 08:00 Rounding strategy PG Doc comments form <noreply@postgresql.org>
2021-04-19 15:37 ` Re: Rounding strategy Laurenz Albe <laurenz.albe@cybertec.at>
2021-04-22 16:54 ` Re: Rounding strategy Laurenz Albe <laurenz.albe@cybertec.at>
2021-04-22 17:50 ` Re: Rounding strategy Tom Lane <tgl@sss.pgh.pa.us>
2021-04-23 07:40 ` Re: Rounding strategy Laurenz Albe <laurenz.albe@cybertec.at>
2021-04-23 08:51 ` Re: Rounding strategy Laurenz Albe <laurenz.albe@cybertec.at>
@ 2021-04-23 16:15 ` rudolphfroger@dreamsolution.nl
0 siblings, 0 replies; 7+ messages in thread
From: rudolphfroger@dreamsolution.nl @ 2021-04-23 16:15 UTC (permalink / raw)
To: pgsql-docs@lists.postgresql.org
Thanks a lot!
Cheers, Rudolph
On 23-04-2021 10:51, Laurenz Albe wrote:
> On Fri, 2021-04-23 at 09:40 +0200, Laurenz Albe wrote:
>> Makes sense. Here is an updated patch.
>
> I see that you have already committed your proposed version.
> Thanks!
>
> Yours,
> Laurenz Albe
>
^ permalink raw reply [nested|flat] 7+ messages in thread
end of thread, other threads:[~2021-04-23 16:15 UTC | newest]
Thread overview: 7+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2021-04-19 08:00 Rounding strategy PG Doc comments form <noreply@postgresql.org>
2021-04-19 15:37 ` Laurenz Albe <laurenz.albe@cybertec.at>
2021-04-22 16:54 ` Laurenz Albe <laurenz.albe@cybertec.at>
2021-04-22 17:50 ` Tom Lane <tgl@sss.pgh.pa.us>
2021-04-23 07:40 ` Laurenz Albe <laurenz.albe@cybertec.at>
2021-04-23 08:51 ` Laurenz Albe <laurenz.albe@cybertec.at>
2021-04-23 16:15 ` rudolphfroger@dreamsolution.nl
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox