add GMP specific isl_val functions
authorSven Verdoolaege <skimo@kotnet.org>
Sat, 6 Apr 2013 08:33:43 +0000 (10:33 +0200)
committerSven Verdoolaege <skimo@kotnet.org>
Tue, 28 May 2013 16:15:04 +0000 (18:15 +0200)
Signed-off-by: Sven Verdoolaege <skimo@kotnet.org>
Makefile.am
doc/user.pod
include/isl/val_gmp.h [new file with mode: 0644]
isl_val_gmp.c [new file with mode: 0644]

index be498c7..bb25f1d 100644 (file)
@@ -138,6 +138,7 @@ libisl_la_SOURCES = \
        isl_union_map.c \
        isl_union_map_private.h \
        isl_val.c \
+       isl_val_gmp.c \
        isl_vec.c \
        isl_version.c \
        isl_vertices_private.h \
@@ -252,6 +253,7 @@ pkginclude_HEADERS = \
        include/isl/union_set.h \
        include/isl/union_set_type.h \
        include/isl/val.h \
+       include/isl/val_gmp.h \
        include/isl/vec.h \
        include/isl/version.h \
        include/isl/vertices.h
index 29bf606..70405ae 100644 (file)
@@ -499,6 +499,27 @@ A value can be printed using
        __isl_give isl_printer *isl_printer_print_val(
                __isl_take isl_printer *p, __isl_keep isl_val *v);
 
+=head3 GMP specific functions
+
+These functions are only available if C<isl> has been compiled with C<GMP>
+support.
+
+Specific integer and rational values can be created from C<GMP> values using
+the following functions.
+
+       #include <isl/val_gmp.h>
+       __isl_give isl_val *isl_val_int_from_gmp(isl_ctx *ctx,
+               mpz_t z);
+       __isl_give isl_val *isl_val_from_gmp(isl_ctx *ctx,
+               const mpz_t n, const mpz_t d);
+
+The numerator and denominator of a rational value can be extracted as
+C<GMP> values using the following functions.
+
+       #include <isl/val_gmp.h>
+       int isl_val_get_num_gmp(__isl_keep isl_val *v, mpz_t z);
+       int isl_val_get_den_gmp(__isl_keep isl_val *v, mpz_t z);
+
 =head2 Integers (obsolescent)
 
 All operations on integers, mainly the coefficients
diff --git a/include/isl/val_gmp.h b/include/isl/val_gmp.h
new file mode 100644 (file)
index 0000000..1dd4da8
--- /dev/null
@@ -0,0 +1,13 @@
+#ifndef ISL_VAL_GMP_H
+#define ISL_VAL_GMP_H
+
+#include <gmp.h>
+#include <isl/val.h>
+
+__isl_give isl_val *isl_val_int_from_gmp(isl_ctx *ctx, mpz_t z);
+__isl_give isl_val *isl_val_from_gmp(isl_ctx *ctx,
+       const mpz_t n, const mpz_t d);
+int isl_val_get_num_gmp(__isl_keep isl_val *v, mpz_t z);
+int isl_val_get_den_gmp(__isl_keep isl_val *v, mpz_t z);
+
+#endif
diff --git a/isl_val_gmp.c b/isl_val_gmp.c
new file mode 100644 (file)
index 0000000..aed8bb1
--- /dev/null
@@ -0,0 +1,64 @@
+#include <isl/val_gmp.h>
+#include <isl_val_private.h>
+
+/* Return a reference to an isl_val representing the integer "z".
+ */
+__isl_give isl_val *isl_val_int_from_gmp(isl_ctx *ctx, mpz_t z)
+{
+       isl_val *v;
+
+       v = isl_val_alloc(ctx);
+       if (!v)
+               return NULL;
+
+       isl_int_set(v->n, z);
+       isl_int_set_si(v->d, 1);
+
+       return v;
+}
+
+/* Return a reference to an isl_val representing the rational value "n"/"d".
+ */
+__isl_give isl_val *isl_val_from_gmp(isl_ctx *ctx, const mpz_t n, const mpz_t d)
+{
+       isl_val *v;
+
+       v = isl_val_alloc(ctx);
+       if (!v)
+               return NULL;
+
+       isl_int_set(v->n, n);
+       isl_int_set(v->d, d);
+
+       return isl_val_normalize(v);
+}
+
+/* Extract the numerator of a rational value "v" in "z".
+ *
+ * If "v" is not a rational value, then the result is undefined.
+ */
+int isl_val_get_num_gmp(__isl_keep isl_val *v, mpz_t z)
+{
+       if (!v)
+               return -1;
+       if (!isl_val_is_rat(v))
+               isl_die(isl_val_get_ctx(v), isl_error_invalid,
+                       "expecting rational value", return -1);
+       mpz_set(z, v->n);
+       return 0;
+}
+
+/* Extract the denominator of a rational value "v" in "z".
+ *
+ * If "v" is not a rational value, then the result is undefined.
+ */
+int isl_val_get_den_gmp(__isl_keep isl_val *v, mpz_t z)
+{
+       if (!v)
+               return -1;
+       if (!isl_val_is_rat(v))
+               isl_die(isl_val_get_ctx(v), isl_error_invalid,
+                       "expecting rational value", return -1);
+       mpz_set(z, v->d);
+       return 0;
+}