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

Remove useless code from do_divide

* libguile/numbers.c (do_divide): Remove code which handled a case
  that never occurs: a zero bignum.
This commit is contained in:
Mark H Weaver 2011-01-26 02:50:03 -05:00 committed by Andy Wingo
parent 41df63cf16
commit a4955a0412

View file

@ -5124,47 +5124,33 @@ do_divide (SCM x, SCM y, int inexact)
} }
else if (SCM_BIGP (y)) else if (SCM_BIGP (y))
{ {
int y_is_zero = (mpz_sgn (SCM_I_BIG_MPZ (y)) == 0); /* big_x / big_y */
if (y_is_zero) if (inexact)
{ {
#ifndef ALLOW_DIVIDE_BY_EXACT_ZERO /* It's easily possible for the ratio x/y to fit a double
scm_num_overflow (s_divide); but one or both x and y be too big to fit a double,
#else hence the use of mpq_get_d rather than converting and
int sgn = mpz_sgn (SCM_I_BIG_MPZ (x)); dividing. */
scm_remember_upto_here_1 (x); mpq_t q;
return (sgn == 0) ? scm_nan () : scm_inf (); *mpq_numref(q) = *SCM_I_BIG_MPZ (x);
#endif *mpq_denref(q) = *SCM_I_BIG_MPZ (y);
return scm_from_double (mpq_get_d (q));
} }
else else
{ {
/* big_x / big_y */ int divisible_p = mpz_divisible_p (SCM_I_BIG_MPZ (x),
if (inexact) SCM_I_BIG_MPZ (y));
{ if (divisible_p)
/* It's easily possible for the ratio x/y to fit a double {
but one or both x and y be too big to fit a double, SCM result = scm_i_mkbig ();
hence the use of mpq_get_d rather than converting and mpz_divexact (SCM_I_BIG_MPZ (result),
dividing. */ SCM_I_BIG_MPZ (x),
mpq_t q; SCM_I_BIG_MPZ (y));
*mpq_numref(q) = *SCM_I_BIG_MPZ (x); scm_remember_upto_here_2 (x, y);
*mpq_denref(q) = *SCM_I_BIG_MPZ (y); return scm_i_normbig (result);
return scm_from_double (mpq_get_d (q)); }
} else
else return scm_i_make_ratio (x, y);
{
int divisible_p = mpz_divisible_p (SCM_I_BIG_MPZ (x),
SCM_I_BIG_MPZ (y));
if (divisible_p)
{
SCM result = scm_i_mkbig ();
mpz_divexact (SCM_I_BIG_MPZ (result),
SCM_I_BIG_MPZ (x),
SCM_I_BIG_MPZ (y));
scm_remember_upto_here_2 (x, y);
return scm_i_normbig (result);
}
else
return scm_i_make_ratio (x, y);
}
} }
} }
else if (SCM_REALP (y)) else if (SCM_REALP (y))