[1] | 1 | #ifndef _BIGNUM_H_
|
---|
| 2 | #define _BIGNUM_H_
|
---|
| 3 |
|
---|
| 4 | #include "internal.h"
|
---|
| 5 |
|
---|
| 6 | typedef struct big_struct bignum;
|
---|
| 7 |
|
---|
| 8 | #define BIG_SIGN_0 0
|
---|
| 9 | #define BIG_SIGN_PLUS 1
|
---|
| 10 | #define BIG_SIGN_MINUS -1
|
---|
| 11 |
|
---|
| 12 | #define BIG_OK 0
|
---|
| 13 | #define BIG_MEMERR 1
|
---|
| 14 | #define BIG_DIV_ZERO 2
|
---|
| 15 | #define BIG_ARGERR 3
|
---|
| 16 |
|
---|
| 17 | #ifdef BIG_SHORT_NAMES
|
---|
| 18 | #define big_set_big big_sb
|
---|
| 19 | #define big_set_long big_sl
|
---|
| 20 | #define big_set_ulong big_usl
|
---|
| 21 | #define big_string big_rs
|
---|
| 22 | #define big_leqp big_lq
|
---|
| 23 | #define big_expt big_x
|
---|
| 24 | #endif
|
---|
| 25 |
|
---|
| 26 | /* External variables to take care about when using the bignums */
|
---|
| 27 | typedef int bigerr_t;
|
---|
| 28 | extern int big_errno;
|
---|
| 29 | extern char *big_end_string;
|
---|
| 30 |
|
---|
| 31 | /* External functions to enable use of bignums */
|
---|
| 32 | extern bigerr_t big_init_pkg(void);
|
---|
| 33 | extern void big_release_pkg(void);
|
---|
| 34 |
|
---|
| 35 | extern bigerr_t big_create(bignum *a);
|
---|
| 36 | extern void big_destroy(bignum *a);
|
---|
| 37 |
|
---|
| 38 | extern unsigned long big_bitcount(bignum *a);
|
---|
| 39 |
|
---|
| 40 | extern bigerr_t big_set_big(bignum *a, bignum *b);
|
---|
| 41 | extern void big_set_long(long n, bignum *a);
|
---|
| 42 | extern void big_set_ulong(unsigned long n, bignum *a);
|
---|
| 43 | extern bigerr_t big_set_string(char *numstr, int base, bignum *a);
|
---|
| 44 |
|
---|
| 45 | extern int big_long(bignum *a, long *n);
|
---|
| 46 | extern int big_ulong(bignum *a, unsigned long *n);
|
---|
| 47 | extern char *big_string(bignum *a, int base);
|
---|
| 48 |
|
---|
| 49 | extern int big_sign(bignum *a);
|
---|
| 50 | extern bigerr_t big_abs(bignum *a, bignum *b);
|
---|
| 51 |
|
---|
| 52 | extern bigerr_t big_negate(bignum *a, bignum *b);
|
---|
| 53 |
|
---|
| 54 | extern int big_compare(bignum *a, bignum *b);
|
---|
| 55 | extern int big_lessp(bignum *a, bignum *b);
|
---|
| 56 | extern int big_leqp(bignum *a, bignum *b);
|
---|
| 57 | extern int big_equalp(bignum *a, bignum *b);
|
---|
| 58 | extern int big_geqp(bignum *a, bignum *b);
|
---|
| 59 | extern int big_greaterp(bignum *a, bignum *b);
|
---|
| 60 |
|
---|
| 61 | extern int big_zerop(bignum *a);
|
---|
| 62 | extern int big_evenp(bignum *a);
|
---|
| 63 | extern int big_oddp(bignum *a);
|
---|
| 64 |
|
---|
| 65 | extern bigerr_t big_add(bignum *a, bignum *b, bignum *c);
|
---|
| 66 | extern bigerr_t big_sub(bignum *a, bignum *b, bignum *c);
|
---|
| 67 |
|
---|
| 68 | extern bigerr_t big_mul(bignum *a, bignum *b, bignum *c);
|
---|
| 69 |
|
---|
| 70 | extern bigerr_t big_trunc(bignum *a, bignum *b, bignum *c, bignum *r);
|
---|
| 71 | extern bigerr_t big_floor(bignum *a, bignum *b, bignum *c, bignum *r);
|
---|
| 72 | extern bigerr_t big_ceil(bignum *a, bignum *b, bignum *c, bignum *r);
|
---|
| 73 | extern bigerr_t big_round(bignum *a, bignum *b, bignum *c, bignum *r);
|
---|
| 74 |
|
---|
| 75 | extern bigerr_t big_random(bignum *a, bignum *b);
|
---|
| 76 |
|
---|
| 77 | extern bigerr_t big_expt(bignum *a, unsigned long z, bignum *x);
|
---|
| 78 | extern bigerr_t big_exptmod(bignum *a_in, bignum *z_in, bignum *n, bignum *x);
|
---|
| 79 | extern bigerr_t big_gcd(bignum *a, bignum *b, bignum *g);
|
---|
| 80 |
|
---|
| 81 | #ifndef NULL
|
---|
| 82 | #define NULL 0
|
---|
| 83 | #endif
|
---|
| 84 |
|
---|
| 85 | #endif /* _BIGNUM_H_ */
|
---|