]> granicus.if.org Git - postgresql/commit
Improve cross-platform consistency of Inf/NaN handling in trig functions.
authorTom Lane <tgl@sss.pgh.pa.us>
Fri, 22 Jan 2016 19:50:51 +0000 (14:50 -0500)
committerTom Lane <tgl@sss.pgh.pa.us>
Fri, 22 Jan 2016 19:50:51 +0000 (14:50 -0500)
commitfd5200c3dca0bc725f5848eef7ffff538f4479ed
treeedf633c14c9ab32b3fc95a4333501007b5c8feaa
parent80aa219146c090d46b599ac40d8d63e30532b622
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
src/backend/utils/adt/float.c