Fix bugs in expt and integer-expt
authorMark H Weaver <mhw@netris.org>
Fri, 5 Nov 2010 02:10:02 +0000 (22:10 -0400)
committerAndy Wingo <wingo@pobox.com>
Thu, 20 Jan 2011 22:28:37 +0000 (23:28 +0100)
commit01c7284ae5c30191e3e21afe432f9315520b412f
treece492d42a093d03d4ebd505505fa406b6dd1bfec
parentb1846b7fb31de1bbe126322688ac109fd86a924e
Fix bugs in expt and integer-expt

* libguile/numbers.c (scm_expt): Fix bug that caused expt to throw an
  exception whenever the base was exact and the exponent was an
  inexact integer, e.g. (expt 5 6.0).

  (scm_expt): Fix bug that caused expt to introduce spurious imaginary
  parts in the result when the base was an inexact negative real and
  the exponent was an integer, e.g. (expt -1.0 2)

  (scm_integer_expt, scm_expt): Change behavior of (integer-expt 0 -1),
  and therefore also (expt 0 -1), to return NaN, per R6RS (actually,
  R6RS says we should throw an exception or return an "unspecified
  number object", but for now we use NaN).  Formerly we returned 0, per
  R5RS. R5RS claims that 0^x=0 for all non-zero x, but that's
  mathematically incorrect, and probably an oversight.

  (scm_integer_expt): Consistently throw a wrong-argument-type exception
  when the exponent is inexact.  Formerly, it didn't always check this
  if the base was 0, 1, or -1.

* test-suite/tests/numbers.test ("integer-expt", "expt"): Add tests.
libguile/numbers.c
test-suite/tests/numbers.test