isl_set_coefficients: rename "dim" variable to "space"
[isl.git] / isl_int.h
blob520b48699e0bf625f7dade92ea0425281e6347cf
1 /*
2 * Copyright 2008-2009 Katholieke Universiteit Leuven
4 * Use of this software is governed by the MIT license
6 * Written by Sven Verdoolaege, K.U.Leuven, Departement
7 * Computerwetenschappen, Celestijnenlaan 200A, B-3001 Leuven, Belgium
8 */
10 #ifndef ISL_INT_H
11 #define ISL_INT_H
12 #define ISL_DEPRECATED_INT_H
14 #include <isl/hash.h>
15 #include <isl/printer.h>
16 #include <string.h>
17 #include <gmp.h>
18 #include <isl_config.h>
20 #ifndef mp_get_memory_functions
21 void mp_get_memory_functions(
22 void *(**alloc_func_ptr) (size_t),
23 void *(**realloc_func_ptr) (void *, size_t, size_t),
24 void (**free_func_ptr) (void *, size_t));
25 #endif
27 /* isl_int is the basic integer type. It currently always corresponds
28 * to a gmp mpz_t, but in the future, different types such as long long
29 * or cln::cl_I will be supported.
31 typedef mpz_t isl_int;
33 #define isl_int_init(i) mpz_init(i)
34 #define isl_int_clear(i) mpz_clear(i)
36 #define isl_int_set(r,i) mpz_set(r,i)
37 #define isl_int_set_gmp(r,i) mpz_set(r,i)
38 #define isl_int_set_si(r,i) mpz_set_si(r,i)
39 #define isl_int_set_ui(r,i) mpz_set_ui(r,i)
40 #define isl_int_get_gmp(i,g) mpz_set(g,i)
41 #define isl_int_fits_slong(r) mpz_fits_slong_p(r)
42 #define isl_int_get_si(r) mpz_get_si(r)
43 #define isl_int_fits_ulong(r) mpz_fits_ulong_p(r)
44 #define isl_int_get_ui(r) mpz_get_ui(r)
45 #define isl_int_get_d(r) mpz_get_d(r)
46 #define isl_int_get_str(r) mpz_get_str(0, 10, r)
47 typedef void (*isl_int_print_gmp_free_t)(void *, size_t);
48 #define isl_int_free_str(s) \
49 do { \
50 isl_int_print_gmp_free_t gmp_free; \
51 mp_get_memory_functions(NULL, NULL, &gmp_free); \
52 (*gmp_free)(s, strlen(s) + 1); \
53 } while (0)
54 #define isl_int_abs(r,i) mpz_abs(r,i)
55 #define isl_int_neg(r,i) mpz_neg(r,i)
56 #define isl_int_swap(i,j) mpz_swap(i,j)
57 #define isl_int_swap_or_set(i,j) mpz_swap(i,j)
58 #define isl_int_add_ui(r,i,j) mpz_add_ui(r,i,j)
59 #define isl_int_sub_ui(r,i,j) mpz_sub_ui(r,i,j)
61 #define isl_int_add(r,i,j) mpz_add(r,i,j)
62 #define isl_int_sub(r,i,j) mpz_sub(r,i,j)
63 #define isl_int_mul(r,i,j) mpz_mul(r,i,j)
64 #define isl_int_mul_2exp(r,i,j) mpz_mul_2exp(r,i,j)
65 #define isl_int_mul_si(r,i,j) mpz_mul_si(r,i,j)
66 #define isl_int_mul_ui(r,i,j) mpz_mul_ui(r,i,j)
67 #define isl_int_pow_ui(r,i,j) mpz_pow_ui(r,i,j)
68 #define isl_int_addmul(r,i,j) mpz_addmul(r,i,j)
69 #define isl_int_addmul_ui(r,i,j) mpz_addmul_ui(r,i,j)
70 #define isl_int_submul(r,i,j) mpz_submul(r,i,j)
71 #define isl_int_submul_ui(r,i,j) mpz_submul_ui(r,i,j)
73 #define isl_int_gcd(r,i,j) mpz_gcd(r,i,j)
74 #ifdef GMP_NORMALIZE_GCDEXT
75 void isl_gmp_gcdext(mpz_t G, mpz_t S, mpz_t T, mpz_t A, mpz_t B);
76 #define isl_int_gcdext(g,x,y,i,j) isl_gmp_gcdext(g,x,y,i,j)
77 #else
78 #define isl_int_gcdext(g,x,y,i,j) mpz_gcdext(g,x,y,i,j)
79 #endif
80 #define isl_int_lcm(r,i,j) mpz_lcm(r,i,j)
81 #define isl_int_divexact(r,i,j) mpz_divexact(r,i,j)
82 #define isl_int_divexact_ui(r,i,j) mpz_divexact_ui(r,i,j)
83 #define isl_int_tdiv_q(r,i,j) mpz_tdiv_q(r,i,j)
84 #define isl_int_cdiv_q(r,i,j) mpz_cdiv_q(r,i,j)
85 #define isl_int_fdiv_q(r,i,j) mpz_fdiv_q(r,i,j)
86 #define isl_int_fdiv_r(r,i,j) mpz_fdiv_r(r,i,j)
87 #define isl_int_fdiv_q_ui(r,i,j) mpz_fdiv_q_ui(r,i,j)
89 #define isl_int_read(r,s) mpz_set_str(r,s,10)
90 #define isl_int_print(out,i,width) \
91 do { \
92 char *s; \
93 s = mpz_get_str(0, 10, i); \
94 fprintf(out, "%*s", width, s); \
95 isl_int_free_str(s); \
96 } while (0)
98 #define isl_int_sgn(i) mpz_sgn(i)
99 #define isl_int_cmp(i,j) mpz_cmp(i,j)
100 #define isl_int_cmp_si(i,si) mpz_cmp_si(i,si)
101 #define isl_int_eq(i,j) (mpz_cmp(i,j) == 0)
102 #define isl_int_ne(i,j) (mpz_cmp(i,j) != 0)
103 #define isl_int_lt(i,j) (mpz_cmp(i,j) < 0)
104 #define isl_int_le(i,j) (mpz_cmp(i,j) <= 0)
105 #define isl_int_gt(i,j) (mpz_cmp(i,j) > 0)
106 #define isl_int_ge(i,j) (mpz_cmp(i,j) >= 0)
107 #define isl_int_abs_eq(i,j) (mpz_cmpabs(i,j) == 0)
108 #define isl_int_abs_ne(i,j) (mpz_cmpabs(i,j) != 0)
109 #define isl_int_abs_lt(i,j) (mpz_cmpabs(i,j) < 0)
110 #define isl_int_abs_gt(i,j) (mpz_cmpabs(i,j) > 0)
111 #define isl_int_abs_ge(i,j) (mpz_cmpabs(i,j) >= 0)
114 #define isl_int_is_zero(i) (isl_int_sgn(i) == 0)
115 #define isl_int_is_one(i) (isl_int_cmp_si(i,1) == 0)
116 #define isl_int_is_negone(i) (isl_int_cmp_si(i,-1) == 0)
117 #define isl_int_is_pos(i) (isl_int_sgn(i) > 0)
118 #define isl_int_is_neg(i) (isl_int_sgn(i) < 0)
119 #define isl_int_is_nonpos(i) (isl_int_sgn(i) <= 0)
120 #define isl_int_is_nonneg(i) (isl_int_sgn(i) >= 0)
121 #define isl_int_is_divisible_by(i,j) mpz_divisible_p(i,j)
123 uint32_t isl_gmp_hash(mpz_t v, uint32_t hash);
124 #define isl_int_hash(v,h) isl_gmp_hash(v,h)
126 __isl_give isl_printer *isl_printer_print_isl_int(__isl_take isl_printer *p,
127 isl_int i);
129 #endif