lattice_point.cc: fix #ifndef USE_MODULO code path
[barvinok.git] / polysign_polylib.c
blobb7e7f8126c296f4c1034b4196212ee622551286b
1 #include <barvinok/util.h>
2 #include "polysign.h"
4 static enum order_sign interval_minmax(Polyhedron *I)
6 int i;
7 int min = 1;
8 int max = -1;
9 assert(I->Dimension == 1);
10 POL_ENSURE_VERTICES(I);
11 for (i = 0; i < I->NbRays; ++i) {
12 if (value_pos_p(I->Ray[i][1]))
13 max = 1;
14 else if (value_neg_p(I->Ray[i][1]))
15 min = -1;
16 else {
17 if (max < 0)
18 max = 0;
19 if (min > 0)
20 min = 0;
23 if (min > 0)
24 return order_gt;
25 if (max < 0)
26 return order_lt;
27 if (min == max)
28 return order_eq;
29 if (max == 0)
30 return order_le;
31 if (min == 0)
32 return order_ge;
33 return order_unknown;
36 /* Returns the sign of the affine function specified by T on the polyhedron D */
37 enum order_sign PL_polyhedron_affine_sign(Polyhedron *D, Matrix *T,
38 struct barvinok_options *options)
40 enum order_sign sign;
41 Polyhedron *I = Polyhedron_Image(D, T, options->MaxRays);
42 if (POL_ISSET(options->MaxRays, POL_INTEGER))
43 I = DomainConstraintSimplify(I, options->MaxRays);
44 if (emptyQ2(I)) {
45 Polyhedron_Free(I);
46 I = Polyhedron_Image(D, T, options->MaxRays);
48 sign = interval_minmax(I);
49 Polyhedron_Free(I);
50 return sign;