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