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

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: pgsql-committers(at)postgresql(dot)org
Subject: pgsql: Improve cross-platform consistency of Inf/NaN handling in trig f
Date: 2016-01-22 19:50:56
Message-ID: E1aMhjU-0006Lv-Ux@gemulon.postgresql.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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(-)

Browse pgsql-committers by date

  From Date Subject
Next Message Tom Lane 2016-01-22 20:46:29 pgsql: Add trigonometric functions that work in degrees.
Previous Message Tom Lane 2016-01-22 17:29:31 pgsql: Improve levenshtein() docs.