From 7ea369e5f22d6e3bcf1e55225c0ff356d9cabb2e Mon Sep 17 00:00:00 2001 From: Paul Eggert Date: Sat, 18 Aug 2018 23:06:41 -0700 Subject: [PATCH] Tweak integer division * src/data.c (arith_driver): Reorder to remove unnecessary FIXNUMP. Tighten test for whether to convert the divisor from fixnum to mpz_t. Simplify. --- src/data.c | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/src/data.c b/src/data.c index 5ef0ef85571..8a6975da3ab 100644 --- a/src/data.c +++ b/src/data.c @@ -2896,11 +2896,11 @@ arith_driver (enum arithop code, ptrdiff_t nargs, Lisp_Object *args) { /* Note that a bignum can never be 0, so we don't need to check that case. */ - if (FIXNUMP (val) && XFIXNUM (val) == 0) - xsignal0 (Qarith_error); if (BIGNUMP (val)) mpz_tdiv_q (accum, accum, XBIGNUM (val)->value); - else if (sizeof (EMACS_INT) > sizeof (long)) + else if (XFIXNUM (val) == 0) + xsignal0 (Qarith_error); + else if (ULONG_MAX < -MOST_NEGATIVE_FIXNUM) { mpz_t tem; mpz_init (tem); @@ -2911,11 +2911,8 @@ arith_driver (enum arithop code, ptrdiff_t nargs, Lisp_Object *args) else { EMACS_INT value = XFIXNUM (val); - bool negate = value < 0; - if (negate) - value = -value; - mpz_tdiv_q_ui (accum, accum, value); - if (negate) + mpz_tdiv_q_ui (accum, accum, eabs (value)); + if (value < 0) mpz_neg (accum, accum); } } -- 2.39.2