From: Dean Rasheed <dean.a.rasheed@gmail.com>
To: pgsql-committers@lists.postgresql.org
Subject: pgsql: Improve the accuracy of numeric power() for integer exponents.
Date: Thu, 20 Oct 2022 09:14:05 +0000
Message-ID: <E1olRcr-003D92-3k@gemulon.postgresql.org> (raw)
Improve the accuracy of numeric power() for integer exponents.
This makes the choice of result scale of numeric power() for integer
exponents consistent with the choice for non-integer exponents, and
with the result scale of other numeric functions. Specifically, the
result scale will be at least as large as the scale of either input,
and sufficient to ensure that the result has at least 16 significant
digits.
Formerly, the result scale was based only on the scale of the first
input, without taking into account the weight of the result. For
results with negative weight, that could lead to results with very few
or even no non-zero significant digits (e.g., 10.0 ^ (-18) produced
0.0000000000000000).
Fix this by moving responsibility for the choice of result scale into
power_var_int(), which already has code to estimate the result weight.
Per report by Adrian Klaver and suggested fix by Tom Lane.
No back-patch -- arguably this is a bug fix, but one which is easy to
work around, so it doesn't seem worth the risk of changing query
results in stable branches.
Discussion: https://postgr.es/m/12a40226-70ac-3a3b-3d3a-fdaf9e32d312%40aklaver.com
Branch
------
master
Details
-------
https://git.postgresql.org/pg/commitdiff/40c7fcbbed5d922e905f8032c5035826d0406980
Modified Files
--------------
src/backend/utils/adt/numeric.c | 110 ++++++----
src/test/regress/expected/numeric.out | 170 ++++++++++------
src/test/regress/expected/numeric_big.out | 324 +++++++++++++++---------------
src/test/regress/sql/numeric.sql | 8 +-
src/test/regress/sql/numeric_big.sql | 152 +++++++-------
5 files changed, 420 insertions(+), 344 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: dean.a.rasheed@gmail.com
Subject: Re: pgsql: Improve the accuracy of numeric power() for integer exponents.
In-Reply-To: <E1olRcr-003D92-3k@gemulon.postgresql.org>
References: <E1olRcr-003D92-3k@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