return obj;
}
+void
+mpz_set_intmax_slow (mpz_t result, intmax_t v)
+{
+ /* If long is larger then a faster path is taken. */
+ eassert (sizeof (intmax_t) > sizeof (long));
+
+ bool negate = false;
+ if (v < 0)
+ {
+ v = -v;
+ negate = true;
+ }
+ mpz_set_uintmax_slow (result, (uintmax_t) v);
+ if (negate)
+ mpz_neg (result, result);
+}
+
+void
+mpz_set_uintmax_slow (mpz_t result, uintmax_t v)
+{
+ /* If long is larger then a faster path is taken. */
+ eassert (sizeof (uintmax_t) > sizeof (unsigned long));
+ /* This restriction could be lifted if needed. */
+ eassert (sizeof (uintmax_t) <= 2 * sizeof (unsigned long));
+
+ mpz_set_ui (result, v >> (CHAR_BIT * sizeof (unsigned long)));
+ mpz_mul_2exp (result, result, CHAR_BIT * sizeof (unsigned long));
+ mpz_add_ui (result, result, v & -1ul);
+}
+
\f
/* Return a newly created vector or string with specified arguments as
elements. If all the arguments are characters that can fit
if (BIGNUMP (val))
mpz_set (accum, XBIGNUM (val)->value);
else
- mpz_set_si (accum, XINT (val));
+ mpz_set_intmax (accum, XINT (val));
if (nargs == 1)
mpz_neg (accum, accum);
}
if (BIGNUMP (val))
mpz_set (accum, XBIGNUM (val)->value);
else
- mpz_set_si (accum, XINT (val));
+ mpz_set_intmax (accum, XINT (val));
}
else
{
else
{
mpz_t tem;
- mpz_init_set_ui (tem, XUINT (val));
+ mpz_init (tem);
+ mpz_set_uintmax (tem, XUINT (val));
mpz_and (accum, accum, tem);
mpz_clear (tem);
}
else
{
mpz_t tem;
- mpz_init_set_ui (tem, XUINT (val));
+ mpz_init (tem);
+ mpz_set_uintmax (tem, XUINT (val));
mpz_ior (accum, accum, tem);
mpz_clear (tem);
}
else
{
mpz_t tem;
- mpz_init_set_ui (tem, XUINT (val));
+ mpz_init (tem);
+ mpz_set_uintmax (tem, XUINT (val));
mpz_xor (accum, accum, tem);
mpz_clear (tem);
}
xmp = &XBIGNUM (x)->value;
else
{
- mpz_init_set_si (xm, XINT (x));
+ mpz_init (xm);
+ mpz_set_intmax (xm, XINT (x));
xmp = &xm;
}
ymp = &XBIGNUM (y)->value;
else
{
- mpz_init_set_si (ym, XINT (y));
+ mpz_init (ym);
+ mpz_set_intmax (ym, XINT (y));
ymp = &ym;
}
xmp = &XBIGNUM (x)->value;
else
{
- mpz_init_set_si (xm, XINT (x));
+ mpz_init (xm);
+ mpz_set_intmax (xm, XINT (x));
xmp = &xm;
}
ymp = &XBIGNUM (y)->value;
else
{
- mpz_init_set_si (ym, XINT (y));
+ mpz_init (ym);
+ mpz_set_intmax (ym, XINT (y));
ymp = &ym;
}
/* Just do the work as bignums to make the code simpler. */
mpz_t result;
eassume (FIXNUMP (value));
+ mpz_init (result);
if (lsh)
- mpz_init_set_ui (result, XUINT (value));
+ mpz_set_uintmax (result, XUINT (value));
else
- mpz_init_set_si (result, XINT (value));
+ mpz_set_intmax (result, XINT (value));
if (XINT (count) >= 0)
mpz_mul_2exp (result, result, XINT (count));
else
else
{
mpz_t num;
- mpz_init_set_si (num, XINT (number) + 1);
+ mpz_init (num);
+ mpz_set_intmax (num, XINT (number) + 1);
number = make_number (num);
mpz_clear (num);
}
else
{
mpz_t num;
- mpz_init_set_si (num, XINT (number) - 1);
+ mpz_init (num);
+ mpz_set_intmax (num, XINT (number) - 1);
number = make_number (num);
mpz_clear (num);
}
extern Lisp_Object make_bignum_str (const char *num, int base);
extern Lisp_Object make_number (mpz_t value);
+extern void mpz_set_intmax_slow (mpz_t result, intmax_t v);
+extern void mpz_set_uintmax_slow (mpz_t result, uintmax_t v);
+
+INLINE void
+mpz_set_intmax (mpz_t result, intmax_t v)
+{
+ /* mpz_set_si works in terms of long, but Emacs may use a wider
+ integer type, and so sometimes will have to construct the mpz_t
+ by hand. */
+ if (sizeof (intmax_t) > sizeof (long) && (long) v != v)
+ mpz_set_intmax_slow (result, v);
+ else
+ mpz_set_si (result, v);
+}
+
+INLINE void
+mpz_set_uintmax (mpz_t result, uintmax_t v)
+{
+ /* mpz_set_ui works in terms of unsigned long, but Emacs may use a
+ wider integer type, and so sometimes will have to construct the
+ mpz_t by hand. */
+ if (sizeof (uintmax_t) > sizeof (unsigned long) && (unsigned long) v != v)
+ mpz_set_uintmax_slow (result, v);
+ else
+ mpz_set_ui (result, v);
+}
/* Build a frequently used 2/3/4-integer lists. */