Handle products with exact 0 differently
authorMark H Weaver <mhw@netris.org>
Tue, 1 Feb 2011 11:30:29 +0000 (06:30 -0500)
committerAndy Wingo <wingo@pobox.com>
Tue, 1 Feb 2011 20:11:12 +0000 (21:11 +0100)
commit5e7918077a4015768a352ab19e4a8e94531bc8aa
tree29b1fdddeb4dfca0511bfa695517e2120354426c
parent55a8b70819100b1341046ab5254f7858bcd74386
Handle products with exact 0 differently

* libguile/numbers.c (scm_product): Handle exact 0 differently.  A
  product containing an exact 0 now returns an exact 0 if and only if
  the other arguments are all exact.  An inexact zero is returned if and
  only if the other arguments are all finite but not all exact.  If an
  infinite or NaN value is present, a NaN value is returned.
  Previously, any product containing an exact 0 yielded an exact 0,
  regardless of the other arguments.

  A note on the rationale for (* 0 0.0) returning 0.0 and not exact 0:
  The exactness propagation rules allow us to return an exact result in
  the presence of inexact arguments only if the values of the inexact
  arguments do not affect the result.  In this case, the value of the
  inexact argument _does_ affect the result, because an infinite or NaN
  value causes the result to be a NaN.

  A note on the rationale for (* 0 +inf.0) being a NaN and not exact 0:
  The R6RS requires that (/ 0 0.0) return a NaN value, and that (/ 0.0)
  return +inf.0.  We would like (/ x y) to be the same as (* x (/ y)),
  and in particular, for (/ 0 0.0) to be the same as (* 0 (/ 0.0)),
  which reduces to (* 0 +inf.0).  Therefore (* 0 +inf.0) should return
  a NaN.

* test-suite/tests/numbers.test: Add many multiplication tests.

* NEWS: Add NEWS entry.
NEWS
libguile/numbers.c
test-suite/tests/numbers.test