mirror of
https://git.savannah.gnu.org/git/guile.git
synced 2025-06-18 01:30:27 +02:00
(scm_abs): Allocate a new real only for negatives, as done for bignums.
This commit is contained in:
parent
753ac1e7e1
commit
ae38324d9c
1 changed files with 8 additions and 1 deletions
|
@ -641,7 +641,14 @@ SCM_PRIMITIVE_GENERIC (scm_abs, "abs", 1, 0, 0,
|
||||||
return x;
|
return x;
|
||||||
}
|
}
|
||||||
else if (SCM_REALP (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))
|
else if (SCM_FRACTIONP (x))
|
||||||
{
|
{
|
||||||
if (SCM_FALSEP (scm_negative_p (SCM_FRACTION_NUMERATOR (x))))
|
if (SCM_FALSEP (scm_negative_p (SCM_FRACTION_NUMERATOR (x))))
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue