1
Fork 0
mirror of https://git.savannah.gnu.org/git/guile.git synced 2025-05-20 19:50:24 +02:00

Use trunc instead of scm_c_truncate

* libguile/numbers.c (scm_c_truncate, scm_truncate_number,
  scm_i_inexact_truncate_quotient, scm_i_inexact_truncate_remainder):
  Use trunc directly, now that we have its gnulib module.
This commit is contained in:
Mark H Weaver 2011-02-14 17:10:03 -05:00 committed by Andy Wingo
parent a6b087be1b
commit c251ab631e

View file

@ -2139,7 +2139,7 @@ scm_i_inexact_truncate_quotient (double x, double y)
if (SCM_UNLIKELY (y == 0)) if (SCM_UNLIKELY (y == 0))
scm_num_overflow (s_scm_truncate_quotient); /* or return a NaN? */ scm_num_overflow (s_scm_truncate_quotient); /* or return a NaN? */
else else
return scm_from_double (scm_c_truncate (x / y)); return scm_from_double (trunc (x / y));
} }
static SCM static SCM
@ -2274,7 +2274,7 @@ scm_i_inexact_truncate_remainder (double x, double y)
if (SCM_UNLIKELY (y == 0)) if (SCM_UNLIKELY (y == 0))
scm_num_overflow (s_scm_truncate_remainder); /* or return a NaN? */ scm_num_overflow (s_scm_truncate_remainder); /* or return a NaN? */
else else
return scm_from_double (x - y * scm_c_truncate (x / y)); return scm_from_double (x - y * trunc (x / y));
} }
static SCM static SCM
@ -8173,14 +8173,7 @@ static SCM scm_divide2real (SCM x, SCM y)
double double
scm_c_truncate (double x) scm_c_truncate (double x)
{ {
#if HAVE_TRUNC
return trunc (x); return trunc (x);
#else
if (x < 0.0)
return ceil (x);
else
return floor (x);
#endif
} }
/* scm_c_round is done using floor(x+0.5) to round to nearest and with /* scm_c_round is done using floor(x+0.5) to round to nearest and with
@ -8233,7 +8226,7 @@ SCM_PRIMITIVE_GENERIC (scm_truncate_number, "truncate", 1, 0, 0,
if (SCM_I_INUMP (x) || SCM_BIGP (x)) if (SCM_I_INUMP (x) || SCM_BIGP (x))
return x; return x;
else if (SCM_REALP (x)) else if (SCM_REALP (x))
return scm_from_double (scm_c_truncate (SCM_REAL_VALUE (x))); return scm_from_double (trunc (SCM_REAL_VALUE (x)));
else if (SCM_FRACTIONP (x)) else if (SCM_FRACTIONP (x))
return scm_truncate_quotient (SCM_FRACTION_NUMERATOR (x), return scm_truncate_quotient (SCM_FRACTION_NUMERATOR (x),
SCM_FRACTION_DENOMINATOR (x)); SCM_FRACTION_DENOMINATOR (x));