blob: eabad628310dcc5564758f255bd2f2f2acbafce5 [file] [log] [blame]
Damien George438c88d2014-02-22 19:25:23 +00001typedef uint16_t mpz_dig_t;
2typedef uint32_t mpz_dbl_dig_t;
3typedef int32_t mpz_dbl_dig_signed_t;
4
5typedef struct _mpz_t {
6 struct {
7 machine_uint_t neg : 1;
8 machine_uint_t alloc : 31;
9 };
10 machine_uint_t len;
11 mpz_dig_t *dig;
12} mpz_t;
13
14bool mpz_int_is_sml_int(int i);
15
16void mpz_init_zero(mpz_t *z);
17void mpz_init_from_int(mpz_t *z, machine_int_t val);
18void mpz_deinit(mpz_t *z);
19
20mpz_t *mpz_zero();
21mpz_t *mpz_from_int(machine_int_t i);
22mpz_t *mpz_from_str(const char *str, uint len, bool neg, uint base);
23void mpz_free(mpz_t *z);
24
25mpz_t *mpz_clone(const mpz_t *src);
26
27void mpz_set(mpz_t *dest, const mpz_t *src);
28void mpz_set_from_int(mpz_t *z, machine_int_t src);
29uint mpz_set_from_str(mpz_t *z, const char *str, uint len, bool neg, uint base);
30
31bool mpz_is_zero(const mpz_t *z);
32bool mpz_is_pos(const mpz_t *z);
33bool mpz_is_neg(const mpz_t *z);
34bool mpz_is_odd(const mpz_t *z);
35bool mpz_is_even(const mpz_t *z);
36
37int mpz_cmp(const mpz_t *lhs, const mpz_t *rhs);
38int mpz_cmp_sml_int(const mpz_t *lhs, int sml_int);
39
40mpz_t *mpz_abs(const mpz_t *z);
41mpz_t *mpz_neg(const mpz_t *z);
42mpz_t *mpz_add(const mpz_t *lhs, const mpz_t *rhs);
43mpz_t *mpz_sub(const mpz_t *lhs, const mpz_t *rhs);
44mpz_t *mpz_mul(const mpz_t *lhs, const mpz_t *rhs);
45mpz_t *mpz_pow(const mpz_t *lhs, const mpz_t *rhs);
46
47void mpz_abs_inpl(mpz_t *dest, const mpz_t *z);
48void mpz_neg_inpl(mpz_t *dest, const mpz_t *z);
49void mpz_add_inpl(mpz_t *dest, const mpz_t *lhs, const mpz_t *rhs);
50void mpz_sub_inpl(mpz_t *dest, const mpz_t *lhs, const mpz_t *rhs);
51void mpz_mul_inpl(mpz_t *dest, const mpz_t *lhs, const mpz_t *rhs);
52void mpz_pow_inpl(mpz_t *dest, const mpz_t *lhs, const mpz_t *rhs);
53
54mpz_t *mpz_gcd(const mpz_t *z1, const mpz_t *z2);
55mpz_t *mpz_lcm(const mpz_t *z1, const mpz_t *z2);
56void mpz_divmod(const mpz_t *lhs, const mpz_t *rhs, mpz_t **quo, mpz_t **rem);
57void mpz_divmod_inpl(mpz_t *dest_quo, mpz_t *dest_rem, const mpz_t *lhs, const mpz_t *rhs);
58mpz_t *mpz_div(const mpz_t *lhs, const mpz_t *rhs);
59mpz_t *mpz_mod(const mpz_t *lhs, const mpz_t *rhs);
60
61int mpz_as_int(const mpz_t *z);
62machine_float_t mpz_as_float(const mpz_t *z);
63uint mpz_as_str_size(const mpz_t *z, uint base);
64char *mpz_as_str(const mpz_t *z, uint base);
65uint mpz_as_str_inpl(const mpz_t *z, uint base, char *str);