pgsql: Improve cross-platform consistency of Inf/NaN handling in trig f - Mailing list pgsql-committers

From Tom Lane
Subject pgsql: Improve cross-platform consistency of Inf/NaN handling in trig f
Date
Msg-id E1aMhjU-0006Lv-Ux@gemulon.postgresql.org
Whole thread Raw
List pgsql-committers
Improve cross-platform consistency of Inf/NaN handling in trig functions.

Ensure that the trig functions return NaN for NaN input regardless of what
the underlying C library functions might do.  Also ensure that an error
is thrown for Inf (or otherwise out-of-range) input, except for atan/atan2
which should accept it.

All these behaviors should now conform to the POSIX spec; previously, all
our popular platforms deviated from that in one case or another.

The main remaining platform dependency here is whether the C library might
choose to throw a domain error for sin/cos/tan inputs that are large but
less than infinity.  (Doing so is not unreasonable, since once a single
unit-in-the-last-place exceeds PI, there can be no significance at all in
the result; however there doesn't seem to be any suggestion in POSIX that
such an error is allowed.)  We will report such errors if they are reported
via "errno", but not if they are reported via "fetestexcept" which is the
other mechanism sanctioned by POSIX.  Some preliminary experiments with
fetestexcept indicated that it might also report errors we could do
without, such as complaining about underflow at an unreasonably large
threshold.  So let's skip that complexity for now.

Dean Rasheed, reviewed by Michael Paquier

Branch
------
master

Details
-------
http://git.postgresql.org/pg/commitdiff/fd5200c3dca0bc725f5848eef7ffff538f4479ed

Modified Files
--------------
src/backend/utils/adt/float.c |  113 ++++++++++++++++++++++++++++++-----------
1 file changed, 84 insertions(+), 29 deletions(-)


pgsql-committers by date:

Previous
From: Tom Lane
Date:
Subject: pgsql: Improve levenshtein() docs.
Next
From: Tom Lane
Date:
Subject: pgsql: Add trigonometric functions that work in degrees.