aboutsummaryrefslogtreecommitdiffstats
path: root/src/alloc.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/alloc.c')
-rw-r--r--src/alloc.c30
1 files changed, 30 insertions, 0 deletions
diff --git a/src/alloc.c b/src/alloc.c
index b775948fd96..1dc1bbb031a 100644
--- a/src/alloc.c
+++ b/src/alloc.c
@@ -3824,6 +3824,36 @@ make_number (mpz_t value)
3824 return obj; 3824 return obj;
3825} 3825}
3826 3826
3827void
3828mpz_set_intmax_slow (mpz_t result, intmax_t v)
3829{
3830 /* If long is larger then a faster path is taken. */
3831 eassert (sizeof (intmax_t) > sizeof (long));
3832
3833 bool negate = false;
3834 if (v < 0)
3835 {
3836 v = -v;
3837 negate = true;
3838 }
3839 mpz_set_uintmax_slow (result, (uintmax_t) v);
3840 if (negate)
3841 mpz_neg (result, result);
3842}
3843
3844void
3845mpz_set_uintmax_slow (mpz_t result, uintmax_t v)
3846{
3847 /* If long is larger then a faster path is taken. */
3848 eassert (sizeof (uintmax_t) > sizeof (unsigned long));
3849 /* This restriction could be lifted if needed. */
3850 eassert (sizeof (uintmax_t) <= 2 * sizeof (unsigned long));
3851
3852 mpz_set_ui (result, v >> (CHAR_BIT * sizeof (unsigned long)));
3853 mpz_mul_2exp (result, result, CHAR_BIT * sizeof (unsigned long));
3854 mpz_add_ui (result, result, v & -1ul);
3855}
3856
3827 3857
3828/* Return a newly created vector or string with specified arguments as 3858/* Return a newly created vector or string with specified arguments as
3829 elements. If all the arguments are characters that can fit 3859 elements. If all the arguments are characters that can fit