Improvements to `log' and `log10'
authorMark H Weaver <mhw@netris.org>
Tue, 15 Feb 2011 15:37:03 +0000 (10:37 -0500)
committerLudovic Courtès <ludo@gnu.org>
Tue, 15 Feb 2011 23:47:34 +0000 (00:47 +0100)
commit05f167beb213e34a3ae849e0008c6fad0871e6ae
tree6745fb62b53ea0d01a937531459d07a6b5f0d3fc
parent14a01ec1a87e0b21356ccd4d737263b8ec0eba13
Improvements to `log' and `log10'

* libguile/numbers.c (log_of_shifted_double, log_of_exact_integer,
  log_of_exact_integer_with_size, log_of_fraction): New internal static
  functions used by scm_log and scm_log10.

  (scm_log, scm_log10): Robustly handle large integers, large and small
  fractions, and fractions close to 1.  Previously, computing logarithms
  of fractions close to 1 yielded grossly inaccurate results, and the
  other cases yielded infinities even though the answer could easily fit
  in a double.  (log -0.0) now returns -inf.0+<PI>i, where previously it
  returned -inf.0.  (log 0) now throws a numerical overflow exception,
  where previously it returned -inf.0.  (log 0.0) still returns -inf.0.
  Analogous changes made to `log10'.

* test-suite/tests/numbers.test (log, log10): Add tests.

Signed-off-by: Ludovic Courtès <ludo@gnu.org>
libguile/numbers.c
test-suite/tests/numbers.test