diff options
author | Paul Eggert <eggert@cs.ucla.edu> | 2018-10-03 09:10:01 -0700 |
---|---|---|
committer | Paul Eggert <eggert@cs.ucla.edu> | 2018-10-06 23:31:04 -0700 |
commit | 84f39d3389209e566dde9acbdd78f5572f0c6751 (patch) | |
tree | ad9788f26ffd9e9ceb7a520ed863833a5b60db8b /src/bignum.h | |
parent | 0faad0a0025cb4c6cbdba44e5b259690fae27b1a (diff) | |
download | emacs-84f39d3389209e566dde9acbdd78f5572f0c6751.tar.gz |
Export converting mpz to [u]intmax
This refactoring will help improve timestamp handling later
(Bug#32902).
* src/bignum.c (mpz_set_uintmax): Move to bignum.h,
and make inline.
(mpz_set_uintmax_slow): Now extern.
(mpz_to_intmax, mpz_to_uintmax): New functions, with
implementation taken from the old bignum_to_intmax
and bignum_to_uintmax.
(bignum_to_intmax, bignum_to_uintmax): Use them.
Diffstat (limited to 'src/bignum.h')
-rw-r--r-- | src/bignum.h | 11 |
1 files changed, 11 insertions, 0 deletions
diff --git a/src/bignum.h b/src/bignum.h index e9cd5c07635..fd035e6e14d 100644 --- a/src/bignum.h +++ b/src/bignum.h @@ -45,7 +45,10 @@ extern mpz_t mpz[4]; extern void init_bignum (void); extern Lisp_Object make_integer_mpz (void); +extern bool mpz_to_intmax (mpz_t const, intmax_t *) ARG_NONNULL ((1, 2)); +extern bool mpz_to_uintmax (mpz_t const, uintmax_t *) ARG_NONNULL ((1, 2)); extern void mpz_set_intmax_slow (mpz_t, intmax_t) ARG_NONNULL ((1)); +extern void mpz_set_uintmax_slow (mpz_t, uintmax_t) ARG_NONNULL ((1)); extern double mpz_get_d_rounded (mpz_t const); INLINE_HEADER_BEGIN @@ -68,6 +71,14 @@ mpz_set_intmax (mpz_t result, intmax_t v) else mpz_set_intmax_slow (result, v); } +INLINE void ARG_NONNULL ((1)) +mpz_set_uintmax (mpz_t result, uintmax_t v) +{ + if (v <= ULONG_MAX) + mpz_set_ui (result, v); + else + mpz_set_uintmax_slow (result, v); +} /* Return a pointer to an mpz_t that is equal to the Lisp integer I. If I is a bignum this returns a pointer to I's representation; |