Fix `min' and `max' handling of NaNs, infinities, and signed zeroes
authorMark H Weaver <mhw@netris.org>
Wed, 2 Feb 2011 06:02:49 +0000 (01:02 -0500)
committerAndy Wingo <wingo@pobox.com>
Wed, 2 Feb 2011 20:21:21 +0000 (21:21 +0100)
commit2e2743113a944108ff8f9ad1becaec26960f5787
treee614d48490c545bc0534228ae3c28cb67ab3b93a
parent09cb3ae237f6563bc5d3189562cfc841784751f2
Fix `min' and `max' handling of NaNs, infinities, and signed zeroes

* libguile/numbers.c (scm_min, scm_max): Properly order the real
  infinities and NaNs, per R6RS, and also take care to handle signed
  zeroes properly.  Note that this ordering is different than that of
  `<', `>', `<=', and `>=', which return #f if any argument is a real
  NaN, and consider the real zeroes to be equal.  The relevant real
  infinity (-inf.0 for min, +inf.0 for max) beats everything, including
  NaNs, and NaNs beat everything else.  Previously these were handled
  improperly in some cases, e.g.:
  (min 1/2 +nan.0) now returns +nan.0 (previously returned 0.5),
  (max 1/2 +nan.0) now returns +nan.0 (previously returned 0.5),
  (min -inf.0 +nan.0) now returns -inf.0 (previously returned +nan.0),
  (max +inf.0 +nan.0) now returns +inf.0 (previously returned +nan.0),
  (min -0.0  0.0) now returns -0.0 (previously returned  0.0),
  (max  0.0 -0.0) now returns  0.0 (previously returned -0.0),
  (max  0   -0.0) now returns  0.0 (previously returned -0.0),
  (max -0.0  0  ) now returns  0.0 (previously returned -0.0).

* test-suite/tests/numbers.test (min, max): Add many more test cases
  relating to NaNs, infinities, and signed zeroes.  Change most existing
  test cases to use `eqv?' instead of `=', in order to check exactness.
libguile/numbers.c
test-suite/tests/numbers.test