1
0
mirror of https://github.com/postgres/postgres.git synced 2025-07-28 23:42:10 +03:00

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
This commit is contained in:
Andrew Gierth
2019-02-13 15:19:44 +00:00
parent 37d9916020
commit f397e08599
13 changed files with 810 additions and 17 deletions

13
configure vendored
View File

@ -15805,6 +15805,19 @@ esac
fi
ac_fn_c_check_func "$LINENO" "strtof" "ac_cv_func_strtof"
if test "x$ac_cv_func_strtof" = xyes; then :
$as_echo "#define HAVE_STRTOF 1" >>confdefs.h
else
case " $LIBOBJS " in
*" strtof.$ac_objext "* ) ;;
*) LIBOBJS="$LIBOBJS strtof.$ac_objext"
;;
esac
fi
case $host_os in