From ae38324d9ccf324c9473ab0ae851cbc473b72de2 Mon Sep 17 00:00:00 2001 From: Kevin Ryde Date: Fri, 21 Nov 2003 00:07:13 +0000 Subject: [PATCH] (scm_abs): Allocate a new real only for negatives, as done for bignums. --- libguile/numbers.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/libguile/numbers.c b/libguile/numbers.c index 3a75aa0af..415e265dc 100644 --- a/libguile/numbers.c +++ b/libguile/numbers.c @@ -641,7 +641,14 @@ SCM_PRIMITIVE_GENERIC (scm_abs, "abs", 1, 0, 0, return x; } else if (SCM_REALP (x)) - return scm_make_real (fabs (SCM_REAL_VALUE (x))); + { + /* note that if x is a NaN then xx<0 is false so we return x unchanged */ + double xx = SCM_REAL_VALUE (x); + if (xx < 0.0) + return scm_make_real (-xx); + else + return x; + } else if (SCM_FRACTIONP (x)) { if (SCM_FALSEP (scm_negative_p (SCM_FRACTION_NUMERATOR (x))))