diff options
-rw-r--r-- | arith.c | 18 | ||||
-rw-r--r-- | mpi/mpi.c | 8 | ||||
-rw-r--r-- | mpi/mpi.h | 14 | ||||
-rw-r--r-- | rand.c | 2 | ||||
-rw-r--r-- | sysif.c | 18 |
5 files changed, 34 insertions, 26 deletions
@@ -779,7 +779,7 @@ static val signum(val anum) { switch (type(anum)) { case BGNUM: - return if3(ISNEG(mp(anum)), negone, one); + return if3(mp_isneg(mp(anum)), negone, one); case FLNUM: { double a = anum->fl.n; @@ -1266,9 +1266,9 @@ tail: cnum a = c_n(anum); if (a == 0) return zero; - if (a < 0 && !ISNEG(mp(bnum))) + if (a < 0 && !mp_isneg(mp(bnum))) return negone; - if (a > 0 && ISNEG(mp(bnum))) + if (a > 0 && mp_isneg(mp(bnum))) return negone; return zero; } @@ -1301,8 +1301,8 @@ tail: goto divzero; if (b < 0) mp_neg(mp(n), mp(n)); - if (rem && ((ISNEG(mp(anum)) && b > 0) || - (!ISNEG(mp(anum)) && b < 0))) + if (rem && ((mp_isneg(mp(anum)) && b > 0) || + (!mp_isneg(mp(anum)) && b < 0))) mpe = mp_sub_d(mp(n), 1, mp(n)); if (mpe != MP_OKAY) do_mp_error(self, mpe); @@ -1320,8 +1320,8 @@ tail: goto divzero; } if (mp_cmp_z(&rem) != MP_EQ && - ((ISNEG(mp(anum)) && b > 0) || - (!ISNEG(mp(anum)) && b < 0))) + ((mp_isneg(mp(anum)) && b > 0) || + (!mp_isneg(mp(anum)) && b < 0))) mpe = mp_sub_d(mp(n), 1, mp(n)); mp_clear(&rem); if (mpe != MP_OKAY) @@ -1356,8 +1356,8 @@ tail: goto divzero; } if (mp_cmp_z(&rem) != MP_EQ && - ((ISNEG(mp(anum)) && !ISNEG(mp(bnum))) || - (!ISNEG(mp(anum)) && ISNEG(mp(bnum))))) + ((mp_isneg(mp(anum)) && !mp_isneg(mp(bnum))) || + (!mp_isneg(mp(anum)) && mp_isneg(mp(bnum))))) mpe = mp_sub_d(mp(n), 1, mp(n)); mp_clear(&rem); if (mpe != MP_OKAY) @@ -74,6 +74,14 @@ static mp_size s_mp_defprec = MP_DEFPREC; #define ARGCHK(X,Y) #endif +/* Nicknames for access macros */ +#define SIGN(MP) mp_sign(MP) +#define ISNEG(MP) mp_isneg(MP) +#define USED(MP) mp_used(MP) +#define ALLOC(MP) mp_alloc(MP) +#define DIGITS(MP) mp_digits(MP) +#define DIGIT(MP,N) mp_digit(MP,N) + /* This defines the maximum I/O base (minimum is 2) */ #define MAX_RADIX 64 @@ -49,12 +49,12 @@ typedef struct { } mp_int; /* Macros for accessing the mp_int internals */ -#define SIGN(MP) ((MP)->sign) -#define ISNEG(MP) ((MP)->sign == MP_NEG) -#define USED(MP) ((MP)->used) -#define ALLOC(MP) ((MP)->alloc) -#define DIGITS(MP) ((MP)->dp) -#define DIGIT(MP,N) (MP)->dp[(N)] +#define mp_sign(MP) ((MP)->sign) +#define mp_isneg(MP) ((MP)->sign == MP_NEG) +#define mp_used(MP) ((MP)->used) +#define mp_alloc(MP) ((MP)->alloc) +#define mp_digits(MP) ((MP)->dp) +#define mp_digit(MP,N) (MP)->dp[(N)] #ifdef __GNUC__ #define mp_nign __attribute__((warn_unused_result)) @@ -68,7 +68,7 @@ void mp_set_prec(mp_size prec); mp_err mp_init(mp_int *mp); INLINE mp_err mp_init_minimal(mp_int *mp) { - DIGITS(mp) = 0; + mp_digits(mp) = 0; return MP_OKAY; } mp_err mp_init_array(mp_int mp[], int count); @@ -255,7 +255,7 @@ val random(val state, val modulus) cobj_handle(self, state, random_state_s)); mp_int *m; - if (bignump(modulus) && !ISNEG(m = mp(modulus))) { + if (bignump(modulus) && !mp_isneg(m = mp(modulus))) { ucnum bits = mp_count_bits(m) - mp_is_pow_two(m); ucnum rands_needed = (bits + 32 - 1) / 32; ucnum msb_rand_bits = bits % 32; @@ -1349,29 +1349,29 @@ off_t off_t_num(val num) mp_int *mpn = mp(num); if (odig > 1) { - if (USED(mpn) > odig) + if (mp_used(mpn) > odig) goto toobig; - if (USED(mpn) == odig && - (DIGITS(mpn)[USED(mpn) - 1] >> (MP_DIGIT_BIT - 1)) != 0) + if (mp_used(mpn) == odig && + (mp_digits(mpn)[mp_used(mpn) - 1] >> (MP_DIGIT_BIT - 1)) != 0) goto toobig; - for (out = 0, i = USED(mpn) - 1; i >= 0; i--) { + for (out = 0, i = mp_used(mpn) - 1; i >= 0; i--) { out <<= MP_DIGIT_BIT * (odig > 1); - out |= DIGITS(mpn)[i]; + out |= mp_digits(mpn)[i]; } - return (ISNEG(mpn)) ? -out : out; + return (mp_isneg(mpn)) ? -out : out; } else { - mp_digit d = DIGITS(mpn)[0]; + mp_digit d = mp_digits(mpn)[0]; - if (USED(mpn) > 1) + if (mp_used(mpn) > 1) goto toobig; if (d > OFF_T_MAX) goto toobig; - return (ISNEG(mpn)) ? d : -d; + return (mp_isneg(mpn)) ? d : -d; } } default: |