diff options
author | Paul Eggert <eggert@cs.ucla.edu> | 2018-09-04 11:49:41 -0700 |
---|---|---|
committer | Paul Eggert <eggert@cs.ucla.edu> | 2018-09-04 11:50:54 -0700 |
commit | 21637d5e5b29d5ec8fb966c0ddfbfba3eb33da38 (patch) | |
tree | e0d7a0b9edac17b7fd6f7dc876e1ed97082dae0e /src/floatfns.c | |
parent | 628f6a2c7a9fe476b7e71efed3a8f8784a00cc54 (diff) | |
download | emacs-21637d5e5b29d5ec8fb966c0ddfbfba3eb33da38.tar.gz emacs-21637d5e5b29d5ec8fb966c0ddfbfba3eb33da38.tar.bz2 emacs-21637d5e5b29d5ec8fb966c0ddfbfba3eb33da38.zip |
Fix (round FLOAT BIGNUM) bug
* src/floatfns.c (rounding_driver): Fix bug when one
argument is a float and the other is a bignum.
* test/src/floatfns-tests.el (bignum-round): Test for the bug.
Diffstat (limited to 'src/floatfns.c')
-rw-r--r-- | src/floatfns.c | 7 |
1 files changed, 5 insertions, 2 deletions
diff --git a/src/floatfns.c b/src/floatfns.c index 2f33b8652b2..13ab7b0359f 100644 --- a/src/floatfns.c +++ b/src/floatfns.c @@ -355,6 +355,8 @@ rounding_driver (Lisp_Object arg, Lisp_Object divisor, CHECK_NUMBER (divisor); if (!FLOATP (arg) && !FLOATP (divisor)) { + /* Divide as integers. Converting to double might lose + info, even for fixnums; also see the FIXME below. */ if (EQ (divisor, make_fixnum (0))) xsignal0 (Qarith_error); int_divide (mpz[0], @@ -363,10 +365,11 @@ rounding_driver (Lisp_Object arg, Lisp_Object divisor, return make_integer_mpz (); } - double f1 = FLOATP (arg) ? XFLOAT_DATA (arg) : XFIXNUM (arg); - double f2 = FLOATP (divisor) ? XFLOAT_DATA (divisor) : XFIXNUM (divisor); + double f1 = XFLOATINT (arg); + double f2 = XFLOATINT (divisor); if (! IEEE_FLOATING_POINT && f2 == 0) xsignal0 (Qarith_error); + /* FIXME: This division rounds, so the result is double-rounded. */ d = f1 / f2; } |