summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Llorens <lloda@sarc.name>2022-01-10 12:21:26 +0100
committerAndy Wingo <wingo@pobox.com>2022-01-13 09:37:17 +0100
commit6058d9e05ddd1350228c2d83485a5bd7484a509c (patch)
tree7a4b7096f817b30e1a400cc6a9ab71b59700b408
parent9e5aa173c79b2f14c8a1ffe758a91a63f52cc3b7 (diff)
downloadguile-6058d9e05ddd1350228c2d83485a5bd7484a509c.tar.gz
Simplify scm_abs for the real case
* libguile/numbers.c (scm_abs): As stated. When x is a nan with the sign bit set, this changes the behavior of (magnitude x) back to what it was in 3.0.7, to clear that bit.
-rw-r--r--libguile/numbers.c12
1 files changed, 1 insertions, 11 deletions
diff --git a/libguile/numbers.c b/libguile/numbers.c
index 9ff870aa7..1a96d9c8c 100644
--- a/libguile/numbers.c
+++ b/libguile/numbers.c
@@ -658,17 +658,7 @@ SCM_PRIMITIVE_GENERIC (scm_abs, "abs", 1, 0, 0,
if (SCM_I_INUMP (x))
return scm_integer_abs_i (SCM_I_INUM (x));
else if (SCM_LIKELY (SCM_REALP (x)))
- {
- double xx = SCM_REAL_VALUE (x);
- /* If x is a NaN then xx<0 is false so we return x unchanged */
- if (xx < 0.0)
- return scm_i_from_double (-xx);
- /* Handle signed zeroes properly */
- else if (SCM_UNLIKELY (xx == 0.0))
- return flo0;
- else
- return x;
- }
+ return scm_i_from_double (copysign (SCM_REAL_VALUE (x), 1.0));
else if (SCM_BIGP (x))
return scm_integer_abs_z (scm_bignum (x));
else if (SCM_FRACTIONP (x))