From: Andrew Gierth <rhodiumtoad@postgresql.org>
To: pgsql-committers@lists.postgresql.org
Subject: pgsql: Use strtof() and not strtod() for float4 input.
Date: Wed, 13 Feb 2019 15:36:34 +0000
Message-ID: <E1gtwaQ-0001Kh-4D@gemulon.postgresql.org> (raw)
Use strtof() and not strtod() for float4 input.
Using strtod() creates a double-rounding problem; the input decimal
value is first rounded to the nearest double; rounding that to the
nearest float may then give an incorrect result.
An example is that 7.038531e-26 when input via strtod and then rounded
to float4 gives 0xAE43FEp-107 instead of the correct 0xAE43FDp-107.
Values output by earlier PG versions with extra_float_digits=3 should
all be read in with the same values as previously. However, values
supplied by other software using shortest representations could be
mis-read.
On platforms that lack a strtof() entirely, we fall back to the old
incorrect rounding behavior. (As strtof() is required by C99, such
platforms are considered of primarily historical interest.) On VS2013,
some workarounds are used to get correct error handling.
The regression tests now test for the correct input values, so
platforms that lack strtof() will need resultmap entries. An entry for
HP-UX 10 is included (more may be needed).
Reviewed-By: Tom Lane
Discussion: https://postgr.es/m/871s5emitx.fsf@news-spur.riddles.org.uk
Discussion: https://postgr.es/m/87d0owlqpv.fsf@news-spur.riddles.org.uk
Branch
------
master
Details
-------
https://git.postgresql.org/pg/commitdiff/f397e08599a3c3c08b3af3b318c531db5882f57d
Modified Files
--------------
configure | 13 +
configure.in | 1 +
src/backend/utils/adt/float.c | 56 ++-
src/include/pg_config.h.in | 3 +
src/include/pg_config.h.win32 | 3 +
src/include/port.h | 4 +
src/include/port/win32_port.h | 12 +
src/port/strtof.c | 123 ++++++
.../regress/expected/float4-misrounded-input.out | 436 +++++++++++++++++++++
src/test/regress/expected/float4.out | 136 ++++++-
src/test/regress/resultmap | 1 +
src/test/regress/sql/float4.sql | 37 ++
src/tools/msvc/Mkvcbuild.pm | 2 +
13 files changed, 810 insertions(+), 17 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: rhodiumtoad@postgresql.org
Subject: Re: pgsql: Use strtof() and not strtod() for float4 input.
In-Reply-To: <E1gtwaQ-0001Kh-4D@gemulon.postgresql.org>
References: <E1gtwaQ-0001Kh-4D@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