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 void evalue_denom(evalue
*e
, Value
*d
)
12 if (value_notzero_p(e
->d
)) {
13 value_lcm(*d
, e
->d
, d
);
16 int offset
= type_offset(e
->x
.p
);
17 for (int i
= e
->x
.p
->size
-1; i
>= offset
; --i
)
18 evalue_denom(&e
->x
.p
->arr
[i
], d
);
21 static void evalue_print(std::ostream
& o
, evalue
*e
, char **p
, int d
)
23 if (value_notzero_p(e
->d
)) {
24 o
<< VALUE_TO_INT(e
->x
.n
) * (d
/ VALUE_TO_INT(e
->d
));
27 assert(e
->x
.p
->type
== polynomial
|| e
->x
.p
->type
== flooring
||
28 e
->x
.p
->type
== fractional
);
29 int offset
= type_offset(e
->x
.p
);
30 for (int i
= e
->x
.p
->size
-1; i
>= offset
; --i
) {
31 if (EVALUE_IS_ZERO(e
->x
.p
->arr
[i
]))
33 if (i
!= e
->x
.p
->size
-1 &&
34 (value_zero_p(e
->x
.p
->arr
[i
].d
) ||
35 value_pos_p(e
->x
.p
->arr
[i
].x
.n
)))
37 if (i
== offset
|| !(value_one_p(e
->x
.p
->arr
[i
].x
.n
) &&
38 d
== VALUE_TO_INT(e
->x
.p
->arr
[i
].d
))) {
39 if (value_zero_p(e
->x
.p
->arr
[i
].d
))
41 evalue_print(o
, &e
->x
.p
->arr
[i
], p
, d
);
42 if (value_zero_p(e
->x
.p
->arr
[i
].d
))
47 for (int j
= 0; j
< i
-offset
; ++j
) {
50 if (e
->x
.p
->type
== flooring
) {
52 evalue_print(o
, &e
->x
.p
->arr
[0], p
);
54 } else if (e
->x
.p
->type
== fractional
) {
56 evalue_print(o
, &e
->x
.p
->arr
[0], p
);
59 o
<< p
[e
->x
.p
->pos
-1];
64 void evalue_print(std::ostream
& o
, evalue
*e
, char **p
)
70 if (value_notone_p(d
))
72 evalue_print(o
, e
, p
, VALUE_TO_INT(d
));
73 if (value_notone_p(d
))
74 o
<< ")/" << VALUE_TO_INT(d
);