1
0
mirror of https://git.savannah.gnu.org/git/emacs.git synced 2024-12-17 10:06:13 +00:00

Make abs handle bignums

* src/floatfns.c (Fabs): Handle bignums.
* test/src/floatfns-tests.el (bignum-abs): New test.
This commit is contained in:
Tom Tromey 2018-07-05 13:19:32 -06:00
parent 872faabbd8
commit 025adce2cf
2 changed files with 21 additions and 2 deletions

View File

@ -275,9 +275,24 @@ DEFUN ("abs", Fabs, Sabs, 1, 1, 0,
doc: /* Return the absolute value of ARG. */)
(register Lisp_Object arg)
{
CHECK_FIXNUM_OR_FLOAT (arg);
CHECK_NUMBER (arg);
if (FLOATP (arg))
if (BIGNUMP (arg))
{
mpz_t val;
mpz_init (val);
mpz_abs (val, XBIGNUM (arg)->value);
arg = make_number (val);
mpz_clear (val);
}
else if (FIXNUMP (arg) && XINT (arg) == MOST_NEGATIVE_FIXNUM)
{
mpz_t val;
mpz_init_set_si (val, - MOST_NEGATIVE_FIXNUM);
arg = make_number (val);
mpz_clear (val);
}
else if (FLOATP (arg))
arg = make_float (fabs (XFLOAT_DATA (arg)));
else if (XINT (arg) < 0)
XSETINT (arg, - XINT (arg));

View File

@ -38,4 +38,8 @@
(should (eql (float (+ most-positive-fixnum 1))
(+ (float most-positive-fixnum) 1))))
(ert-deftest bignum-abs ()
(should (= most-positive-fixnum
(- (abs most-negative-fixnum) 1))))
(provide 'floatfns-tests)