aboutsummaryrefslogtreecommitdiffstats
path: root/src/data.c
diff options
context:
space:
mode:
authorPaul Eggert2018-08-22 19:30:24 -0700
committerPaul Eggert2018-08-22 19:30:57 -0700
commitee641b87cf220250ba89f219fb47a4406a05deb7 (patch)
tree08ff44c5197ae39b2ec0906de4bb4dcafda4677f /src/data.c
parentbe5fe6183e95f3afe3a62ec43504b99df90bc794 (diff)
downloademacs-ee641b87cf220250ba89f219fb47a4406a05deb7.tar.gz
emacs-ee641b87cf220250ba89f219fb47a4406a05deb7.zip
Fix bugs when rounding to bignums
Also, since Emacs historically reported a range error when rounding operations overflowed, do that consistently for all bignum overflows. * doc/lispref/errors.texi (Standard Errors): * doc/lispref/numbers.texi (Integer Basics): Document range errors. * src/alloc.c (range_error): Rename from integer_overflow. All uses changed. * src/floatfns.c (rounding_driver): When the result of a floating point rounding operation does not fit into a fixnum, put it into a bignum instead of always signaling an range error. * test/src/floatfns-tests.el (divide-extreme-sign): These tests now return the mathematically-correct answer instead of signaling an error. (bignum-round): Check that integers round to themselves.
Diffstat (limited to 'src/data.c')
-rw-r--r--src/data.c8
1 files changed, 4 insertions, 4 deletions
diff --git a/src/data.c b/src/data.c
index 08c7271dd79..170a74a6589 100644
--- a/src/data.c
+++ b/src/data.c
@@ -2406,7 +2406,7 @@ static void
2406emacs_mpz_mul (mpz_t rop, mpz_t const op1, mpz_t const op2) 2406emacs_mpz_mul (mpz_t rop, mpz_t const op1, mpz_t const op2)
2407{ 2407{
2408 if (NLIMBS_LIMIT - emacs_mpz_size (op1) < emacs_mpz_size (op2)) 2408 if (NLIMBS_LIMIT - emacs_mpz_size (op1) < emacs_mpz_size (op2))
2409 integer_overflow (); 2409 range_error ();
2410 mpz_mul (rop, op1, op2); 2410 mpz_mul (rop, op1, op2);
2411} 2411}
2412 2412
@@ -2420,7 +2420,7 @@ emacs_mpz_mul_2exp (mpz_t rop, mpz_t const op1, mp_bitcnt_t op2)
2420 2420
2421 mp_bitcnt_t op2limbs = op2 / GMP_NUMB_BITS; 2421 mp_bitcnt_t op2limbs = op2 / GMP_NUMB_BITS;
2422 if (lim - emacs_mpz_size (op1) < op2limbs) 2422 if (lim - emacs_mpz_size (op1) < op2limbs)
2423 integer_overflow (); 2423 range_error ();
2424 mpz_mul_2exp (rop, op1, op2); 2424 mpz_mul_2exp (rop, op1, op2);
2425} 2425}
2426 2426
@@ -2434,7 +2434,7 @@ emacs_mpz_pow_ui (mpz_t rop, mpz_t const base, unsigned long exp)
2434 2434
2435 int nbase = emacs_mpz_size (base), n; 2435 int nbase = emacs_mpz_size (base), n;
2436 if (INT_MULTIPLY_WRAPV (nbase, exp, &n) || lim < n) 2436 if (INT_MULTIPLY_WRAPV (nbase, exp, &n) || lim < n)
2437 integer_overflow (); 2437 range_error ();
2438 mpz_pow_ui (rop, base, exp); 2438 mpz_pow_ui (rop, base, exp);
2439} 2439}
2440 2440
@@ -3398,7 +3398,7 @@ expt_integer (Lisp_Object x, Lisp_Object y)
3398 && mpz_fits_ulong_p (XBIGNUM (y)->value)) 3398 && mpz_fits_ulong_p (XBIGNUM (y)->value))
3399 exp = mpz_get_ui (XBIGNUM (y)->value); 3399 exp = mpz_get_ui (XBIGNUM (y)->value);
3400 else 3400 else
3401 integer_overflow (); 3401 range_error ();
3402 3402
3403 mpz_t val; 3403 mpz_t val;
3404 mpz_init (val); 3404 mpz_init (val);