add isl_aff_get_constant_val
[isl.git] / isl_val_gmp.c
blobaed8bb1824b88f31d0d9693a89a1d4b9988a1f45
1 #include <isl/val_gmp.h>
2 #include <isl_val_private.h>
4 /* Return a reference to an isl_val representing the integer "z".
5 */
6 __isl_give isl_val *isl_val_int_from_gmp(isl_ctx *ctx, mpz_t z)
8 isl_val *v;
10 v = isl_val_alloc(ctx);
11 if (!v)
12 return NULL;
14 isl_int_set(v->n, z);
15 isl_int_set_si(v->d, 1);
17 return v;
20 /* Return a reference to an isl_val representing the rational value "n"/"d".
22 __isl_give isl_val *isl_val_from_gmp(isl_ctx *ctx, const mpz_t n, const mpz_t d)
24 isl_val *v;
26 v = isl_val_alloc(ctx);
27 if (!v)
28 return NULL;
30 isl_int_set(v->n, n);
31 isl_int_set(v->d, d);
33 return isl_val_normalize(v);
36 /* Extract the numerator of a rational value "v" in "z".
38 * If "v" is not a rational value, then the result is undefined.
40 int isl_val_get_num_gmp(__isl_keep isl_val *v, mpz_t z)
42 if (!v)
43 return -1;
44 if (!isl_val_is_rat(v))
45 isl_die(isl_val_get_ctx(v), isl_error_invalid,
46 "expecting rational value", return -1);
47 mpz_set(z, v->n);
48 return 0;
51 /* Extract the denominator of a rational value "v" in "z".
53 * If "v" is not a rational value, then the result is undefined.
55 int isl_val_get_den_gmp(__isl_keep isl_val *v, mpz_t z)
57 if (!v)
58 return -1;
59 if (!isl_val_is_rat(v))
60 isl_die(isl_val_get_ctx(v), isl_error_invalid,
61 "expecting rational value", return -1);
62 mpz_set(z, v->d);
63 return 0;