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));
(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)