Commit 0d868917 authored by Tom Tromey's avatar Tom Tromey
Browse files

Make 1+ and 1- handle bignums

* src/data.c (Fadd1, Fsub1): Handle bignums.
* test/src/data-tests.el (data-tests-1+, data-tests-1-): New tests.
parent 025adce2
......@@ -3239,12 +3239,32 @@ DEFUN ("1+", Fadd1, Sadd1, 1, 1, 0,
Markers are converted to integers. */)
(register Lisp_Object number)
{
CHECK_FIXNUM_OR_FLOAT_COERCE_MARKER (number);
CHECK_NUMBER_COERCE_MARKER (number);
if (FLOATP (number))
return (make_float (1.0 + XFLOAT_DATA (number)));
XSETINT (number, XINT (number) + 1);
if (BIGNUMP (number))
{
mpz_t num;
mpz_init (num);
mpz_add_ui (num, XBIGNUM (number)->value, 1);
number = make_number (num);
mpz_clear (num);
}
else
{
eassume (FIXNUMP (number));
if (XINT (number) < MOST_POSITIVE_FIXNUM)
XSETINT (number, XINT (number) + 1);
else
{
mpz_t num;
mpz_init_set_si (num, XINT (number) + 1);
number = make_number (num);
mpz_clear (num);
}
}
return number;
}
......@@ -3253,12 +3273,32 @@ DEFUN ("1-", Fsub1, Ssub1, 1, 1, 0,
Markers are converted to integers. */)
(register Lisp_Object number)
{
CHECK_FIXNUM_OR_FLOAT_COERCE_MARKER (number);
CHECK_NUMBER_COERCE_MARKER (number);
if (FLOATP (number))
return (make_float (-1.0 + XFLOAT_DATA (number)));
XSETINT (number, XINT (number) - 1);
if (BIGNUMP (number))
{
mpz_t num;
mpz_init (num);
mpz_sub_ui (num, XBIGNUM (number)->value, 1);
number = make_number (num);
mpz_clear (num);
}
else
{
eassume (FIXNUMP (number));
if (XINT (number) > MOST_POSITIVE_FIXNUM)
XSETINT (number, XINT (number) - 1);
else
{
mpz_t num;
mpz_init_set_si (num, XINT (number) - 1);
number = make_number (num);
mpz_clear (num);
}
}
return number;
}
......
......@@ -579,4 +579,12 @@ comparing the subr with a much slower lisp implementation."
(v (read s)))
(should (equal (number-to-string v) s))))
(ert-deftest data-tests-1+ ()
(should (> (1+ most-positive-fixnum) most-positive-fixnum))
(should (fixnump (1+ (1- most-negative-fixnum)))))
(ert-deftest data-tests-1- ()
(should (< (1- most-negative-fixnum) most-negative-fixnum))
(should (fixnump (1- (1+ most-positive-fixnum)))))
;;; data-tests.el ends here
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment