diff options
Diffstat (limited to 'src/bignum.c')
| -rw-r--r-- | src/bignum.c | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/src/bignum.c b/src/bignum.c index 51d90ffaefa..859896cdcf7 100644 --- a/src/bignum.c +++ b/src/bignum.c | |||
| @@ -431,3 +431,39 @@ make_bignum_str (char const *num, int base) | |||
| 431 | eassert (check == 0); | 431 | eassert (check == 0); |
| 432 | return make_lisp_ptr (b, Lisp_Vectorlike); | 432 | return make_lisp_ptr (b, Lisp_Vectorlike); |
| 433 | } | 433 | } |
| 434 | |||
| 435 | /* Check that X is a Lisp integer in the range LO..HI. | ||
| 436 | Return X's value as an intmax_t. */ | ||
| 437 | |||
| 438 | intmax_t | ||
| 439 | check_integer_range (Lisp_Object x, intmax_t lo, intmax_t hi) | ||
| 440 | { | ||
| 441 | CHECK_INTEGER (x); | ||
| 442 | intmax_t i; | ||
| 443 | if (! (integer_to_intmax (x, &i) && lo <= i && i <= hi)) | ||
| 444 | args_out_of_range_3 (x, make_int (lo), make_int (hi)); | ||
| 445 | return i; | ||
| 446 | } | ||
| 447 | |||
| 448 | /* Check that X is a Lisp integer in the range 0..HI. | ||
| 449 | Return X's value as an uintmax_t. */ | ||
| 450 | |||
| 451 | uintmax_t | ||
| 452 | check_uinteger_max (Lisp_Object x, uintmax_t hi) | ||
| 453 | { | ||
| 454 | CHECK_INTEGER (x); | ||
| 455 | uintmax_t i; | ||
| 456 | if (! (integer_to_uintmax (x, &i) && i <= hi)) | ||
| 457 | args_out_of_range_3 (x, make_fixnum (0), make_uint (hi)); | ||
| 458 | return i; | ||
| 459 | } | ||
| 460 | |||
| 461 | /* Check that X is a Lisp integer no greater than INT_MAX, | ||
| 462 | and return its value or zero, whichever is greater. */ | ||
| 463 | |||
| 464 | int | ||
| 465 | check_int_nonnegative (Lisp_Object x) | ||
| 466 | { | ||
| 467 | CHECK_INTEGER (x); | ||
| 468 | return Fnatnump (x) ? check_integer_range (x, 0, INT_MAX) : 0; | ||
| 469 | } | ||