update isl for help message printing
[barvinok.git] / evalue_util.cc
blob7adcdfcf263802b9c8fc2d7c9013181451e7e728
1 #include <assert.h>
2 #include <barvinok/util.h>
3 #include "evalue_util.h"
5 static int type_offset(enode *p)
7 return p->type == fractional ? 1 :
8 p->type == flooring ? 1 : 0;
11 static void evalue_print(std::ostream& o, evalue *e, char **p, int d)
13 if (value_notzero_p(e->d)) {
14 o << VALUE_TO_INT(e->x.n) * (d / VALUE_TO_INT(e->d));
15 return;
17 assert(e->x.p->type == polynomial || e->x.p->type == flooring ||
18 e->x.p->type == fractional);
19 int offset = type_offset(e->x.p);
20 for (int i = e->x.p->size-1; i >= offset; --i) {
21 if (EVALUE_IS_ZERO(e->x.p->arr[i]))
22 continue;
23 if (i != e->x.p->size-1 &&
24 (value_zero_p(e->x.p->arr[i].d) ||
25 value_pos_p(e->x.p->arr[i].x.n)))
26 o << "+";
27 if (i == offset || !(value_one_p(e->x.p->arr[i].x.n) &&
28 d == VALUE_TO_INT(e->x.p->arr[i].d))) {
29 if (value_zero_p(e->x.p->arr[i].d))
30 o << "(";
31 evalue_print(o, &e->x.p->arr[i], p, d);
32 if (value_zero_p(e->x.p->arr[i].d))
33 o << ")";
34 if (i != offset)
35 o << "*";
37 for (int j = 0; j < i-offset; ++j) {
38 if (j != 0)
39 o << "*";
40 if (e->x.p->type == flooring) {
41 o << "[";
42 evalue_print(o, &e->x.p->arr[0], p);
43 o << "]";
44 } else if (e->x.p->type == fractional) {
45 o << "{";
46 evalue_print(o, &e->x.p->arr[0], p);
47 o << "}";
48 } else
49 o << p[e->x.p->pos-1];
54 void evalue_print(std::ostream& o, evalue *e, char **p)
56 Value d;
57 value_init(d);
58 value_set_si(d, 1);
59 evalue_denom(e, &d);
60 if (value_notone_p(d))
61 o << "(";
62 evalue_print(o, e, p, VALUE_TO_INT(d));
63 if (value_notone_p(d))
64 o << ")/" << VALUE_TO_INT(d);
65 value_clear(d);