static T set(T z, long int n) { if (n == LONG_MIN) XP_fromint(z->size, z->digits, LONG_MAX + 1UL); else if (n < 0) XP_fromint(z->size, z->digits, -n); else XP_fromint(z->size, z->digits, n); z->sign = n < 0 ? -1 : 1; return normalize(z, z->size); }
static int apply(T op(T, T, T), T z, T x, long v) { { T z = tmp[2]; if (v == LONG_MIN) { XP_fromint(nbytes, z, LONG_MAX + 1UL); XP_neg(nbytes, z, z, 1); } else if (v < 0) { XP_fromint(nbytes, z, -v); XP_neg(nbytes, z, z, 1); } else XP_fromint(nbytes, z, v); z[nbytes-1] &= msb; } op(z, x, tmp[2]); return (nbits < 8*(int)sizeof (v) && (v < -(1L<<(nbits-1)) || v >= (1L<<(nbits-1)))); }
T MP_fromint(T z, long v) { assert(z); if (v == LONG_MIN) { XP_fromint(nbytes, z, LONG_MAX + 1UL); XP_neg(nbytes, z, z, 1); } else if (v < 0) { XP_fromint(nbytes, z, -v); XP_neg(nbytes, z, z, 1); } else XP_fromint(nbytes, z, v); z[nbytes-1] &= msb; if ((nbits < 8*(int)sizeof (v) && (v < -(1L<<(nbits-1)) || v >= (1L<<(nbits-1))))) RAISE(MP_Overflow); return z; }
T MP_fromintu(T z, unsigned long u) { unsigned long carry; assert(z); carry = XP_fromint(nbytes, z, u); carry |= z[nbytes-1]&~msb; z[nbytes-1] &= msb; if (carry) RAISE(MP_Overflow); return z; }
static int applyu(T op(T, T, T), T z, T x, unsigned long u) { unsigned long carry; { T z = tmp[2]; carry = XP_fromint(nbytes, z, u); carry |= z[nbytes-1]&~msb; z[nbytes-1] &= msb; } op(z, x, tmp[2]); return carry != 0; }
int MP_cmpui(T x, unsigned long y) { assert(x); if ((int)sizeof y >= nbytes) { unsigned long v = XP_toint(nbytes, x); if (v < y) return -1; else if (v > y) return 1; else return 0; } else { XP_fromint(nbytes, tmp[2], y); return XP_cmp(nbytes, x, tmp[2]); } }