1
Fork 0
mirror of https://git.savannah.gnu.org/git/guile.git synced 2025-06-12 06:41:13 +02:00

(scm_round_number): For inum and big, just return x. For

real, use scm_round for 2^54-1 etc problems covered there.
This commit is contained in:
Kevin Ryde 2004-05-18 23:43:28 +00:00
parent 63947c7ad3
commit bae30667b0

View file

@ -5007,6 +5007,15 @@ SCM_DEFINE (scm_round_number, "round", 1, 0, 0,
"round towards the even one.")
#define FUNC_NAME s_scm_round_number
{
if (SCM_INUMP (x) || SCM_BIGP (x))
return x;
else if (SCM_REALP (x))
return scm_make_real (scm_round (SCM_REAL_VALUE (x)));
else
{
/* OPTIMIZE-ME: Fraction case could be done more efficiently by a
single quotient+remainder division then examining to see which way
the rounding should go. */
SCM plus_half = scm_sum (x, exactly_one_half);
SCM result = scm_floor (plus_half);
/* Adjust so that the scm_round is towards even. */
@ -5016,6 +5025,7 @@ SCM_DEFINE (scm_round_number, "round", 1, 0, 0,
else
return result;
}
}
#undef FUNC_NAME
SCM_PRIMITIVE_GENERIC (scm_floor, "floor", 1, 0, 0,