From: Tom Lane <tgl@sss.pgh.pa.us>
To: pgsql-committers@lists.postgresql.org
Subject: pgsql: Avoid gratuitous inaccuracy in numeric width_bucket().
Date: Thu, 08 Oct 2020 17:06:40 +0000
Message-ID: <E1kQZNI-0001nM-Gu@gemulon.postgresql.org> (raw)
Avoid gratuitous inaccuracy in numeric width_bucket().
Multiply before dividing, not the reverse, so that cases that should
produce exact results do produce exact results. (width_bucket_float8
got this right already.) Even when the result is inexact, this avoids
making it more inexact, since only the division step introduces any
imprecision.
While at it, fix compute_bucket() to not uselessly repeat the sign
check already done by its caller, and avoid duplicating the
multiply/divide steps by adjusting variable usage.
Per complaint from Martin Visser. Although this seems like a bug fix,
I'm hesitant to risk changing width_bucket()'s results in stable
branches, so no back-patch.
Discussion: https://postgr.es/m/6FA5117D-6AED-4656-8FEF-B74AC18FAD85@brytlyt.com
Branch
------
master
Details
-------
https://git.postgresql.org/pg/commitdiff/7538708394e7a70105a4e601e253adf80f47cca8
Modified Files
--------------
src/backend/utils/adt/numeric.c | 31 ++++++++++++++-------------
src/test/regress/expected/numeric.out | 40 +++++++++++++++++++++++++++++++++++
src/test/regress/sql/numeric.sql | 9 ++++++++
3 files changed, 65 insertions(+), 15 deletions(-)
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 from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-committers@postgresql.org
Cc: tgl@sss.pgh.pa.us
Subject: Re: pgsql: Avoid gratuitous inaccuracy in numeric width_bucket().
In-Reply-To: <E1kQZNI-0001nM-Gu@gemulon.postgresql.org>
References: <E1kQZNI-0001nM-Gu@gemulon.postgresql.org>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
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