diff options
author | Daniel Llorens <lloda@sarc.name> | 2022-01-10 13:26:00 +0100 |
---|---|---|
committer | Andy Wingo <wingo@pobox.com> | 2022-01-13 09:37:17 +0100 |
commit | 19bc021e349f4aaff53daa42032025929ee1c0f2 (patch) | |
tree | 10f51fa4f4573dabb9326ebb87fb8619b7debd26 /libguile/numbers.c | |
parent | 4feff820bed83b84acb3267edfcfbc1d18a2bce1 (diff) | |
download | guile-19bc021e349f4aaff53daa42032025929ee1c0f2.tar.gz |
Have log and log10(real nan) return real nan regardless of sign
* libguile/numbers.c (log_of_shifted_double, scm_log10): Avoid complex
extension when the argument is a real nan.
* test-suite/tests/numbers.test: Tests for nans of either sign.
Diffstat (limited to 'libguile/numbers.c')
-rw-r--r-- | libguile/numbers.c | 17 |
1 files changed, 9 insertions, 8 deletions
diff --git a/libguile/numbers.c b/libguile/numbers.c index 83fe027a9..4417f861f 100644 --- a/libguile/numbers.c +++ b/libguile/numbers.c @@ -6967,12 +6967,12 @@ scm_is_number (SCM z) static SCM log_of_shifted_double (double x, long shift) { + /* cf scm_log10 */ double ans = log (fabs (x)) + shift * M_LN2; - - if (copysign (1.0, x) > 0.0) - return scm_i_from_double (ans); - else + if (signbit (x) && SCM_LIKELY (!isnan (x))) return scm_c_make_rectangular (ans, M_PI); + else + return scm_i_from_double (ans); } /* Returns log(n), for exact integer n */ @@ -7081,10 +7081,11 @@ SCM_PRIMITIVE_GENERIC (scm_log10, "log10", 1, 0, 0, { double re = scm_to_double (z); double l = log10 (fabs (re)); - if (copysign (1.0, re) > 0.0) - return scm_i_from_double (l); - else - return scm_c_make_rectangular (l, M_LOG10E * M_PI); + /* cf log_of_shifted_double */ + if (signbit (re) && SCM_LIKELY (!isnan (re))) + return scm_c_make_rectangular (l, M_LOG10E * M_PI); + else + return scm_i_from_double (l); } } else if (SCM_BIGP (z)) |