eval03.gms : test constant compile time evaluation functions

**Description**

Functions: abs ceil cos exp fact floor frac IfThen log log2 log10 max mod mod PI power round sign sin sleep sqr sqrt tan trunc ** ** Additional tests are welcome ** ** ** Contributor: Alex

**Small Model of Type : ** GAMS

**Category :** GAMS Test library

**Main file : ** eval03.gms

```
$title test constant compile time evaluation functions (EVAL03,SEQ=462)
$ontext
Functions:
abs ceil cos exp fact floor frac IfThen log log2
log10 max mod mod PI power round sign sin sleep
sqr sqrt tan trunc
** ** ** Additional tests are welcome ** ** **
Contributor: Alex
$offtext
$ondollar
set f / abs,ceil,cos,exp,fact,floor,frac,ifthen,log,log2,log10,max,min,mod,
power,round,sign,sin,sqr,sqrt,tan,trunc /
c / 1*15 /
v / calculated, expected /;
$onundf
table res(f,c,v) calculated and expected function values
calculated expected
abs.1 [abs(-inf)] inf
abs.2 [abs(+inf)] inf
abs.3 [abs(undf)] undf
ceil.1 [ceil(-inf)] -inf
ceil.2 [ceil(+inf)] inf
ceil.3 [ceil(undf)] undf
ceil.4 [ceil(0)] 0
ceil.5 [ceil(1.5)] 2
ceil.6 [ceil(-1.5)] -1
cos.1 [cos(-inf)] undf
cos.2 [cos(+inf)] undf
cos.3 [cos(undf)] undf
exp.1 [exp(-inf)] 0
exp.2 [exp(+inf)] inf
exp.3 [exp(undf)] undf
exp.4 [exp(0)] 1
fact.1 [fact(-inf)] undf
fact.2 [fact(+inf)] undf
fact.3 [fact(undf)] undf
fact.4 [fact(167)] undf
fact.5 [fact(0)] 1
fact.6 [fact(1)] 1
fact.7 [fact(2)] 2
fact.8 [fact(3)] 6
fact.9 [fact(20)] 2432902008176640000
* the expected values for these next factorials are computed below:
* GAMS will not let us enter large or precise constants
fact.10 [fact(30)] -1
fact.11 [fact(60)] -1
fact.12 [fact(90)] -1
fact.13 [fact(120)] -1
fact.14 [fact(150)] -1
fact.15 [fact(166)] -1
floor.1 [floor(-inf)] -inf
floor.2 [floor(+inf)] inf
floor.3 [floor(undf)] undf
floor.4 [floor(0)] 0
floor.5 [floor(1.5)] 1
floor.6 [floor(-1.5)] -2
frac.1 [frac(-inf)] undf
frac.2 [frac(+inf)] undf
frac.3 [frac(undf)] undf
ifthen.1 [ifthen(-inf,1,2)] 1
ifthen.2 [ifthen(+inf,1,2)] 1
ifthen.3 [ifthen(undf,1,2)] undf
ifthen.4 [ifthen(0,undf,4)] 4
ifthen.5 [ifthen(1,undf,5)] undf
ifthen.6 [ifthen(0,6,undf)] undf
ifthen.7 [ifthen(1,7,undf)] 7
log.1 [log(-inf)] undf
log.2 [log(-1)] undf
log.3 [log(0)] -inf
log.4 [log(+inf)] inf
log.5 [log(undf)] undf
log2.1 [log2(-inf)] undf
log2.2 [log2(-1)] undf
log2.3 [log2(0)] -inf
log2.4 [log2(+inf)] inf
log2.5 [log2(undf)] undf
log10.1 [log10(-inf)] undf
log10.2 [log10(-1)] undf
log10.3 [log10(0)] -inf
log10.4 [log10(+inf)] inf
log10.5 [log10(undf)] undf
max.1 [max(-inf,inf)] inf
max.2 [max(undf,0)] undf
max.3 [max(0,undf)] undf
max.4 [max(-1,1)] 1
max.5 [max(-inf,1)] 1
max.6 [max(inf,1)] inf
max.7 [max(-inf,1,inf)] inf
min.1 [min(-inf,inf)] -inf
min.2 [min(undf,0)] undf
min.3 [min(0,undf)] undf
min.4 [min(-1,1)] -1
min.5 [min(-inf,1)] -inf
min.6 [min(inf,1)] 1
min.7 [min(inf,1,5)] 1
mod.1 [mod(-inf,inf)] undf
mod.2 [mod(undf,0)] undf
mod.3 [mod(0,undf)] undf
mod.4 [mod(-1,1)] 0
mod.5 [mod(-inf,1)] undf
mod.6 [mod(inf,1)] undf
power.1 [power(-inf,inf)] inf
power.2 [power(undf,0)] undf
power.3 [power(0,undf)] undf
power.4 [power(-1,1)] -1
power.5 [power(-inf,2)] inf
power.6 [power(inf,2)] inf
power.7 [power(3,1.5)] undf
power.8 [power(10,0)] 1
power.9 [power(-10,0)] 1
power.10 [power(0,0)] 1
power.11 [power(0.5,inf)] 0
power.12 [power(-0.5,inf)] 0
power.13 [power(0.5,-1)] 2
power.14 [power(-inf,3)] -inf
power.15 [power(0,-inf)] inf
round.1 [round(-inf,inf)] undf
round.2 [round(undf,0)] undf
round.3 [round(55.75,inf)] undf
round.4 [round(inf,2)] inf
round.5 [round(-inf,-10)] -inf
* the 55.55 caused problems, isolated in eval07
* round.6 [round(55.55,1)] 55.5
round.6 [round(55.75,1)] 55.8
round.7 [round(55.75,0)] 56
round.8 [round(55.75,-1)] 60
round.9 [round(55.75,-2)] 100
round.10 [round(55.75,-3)] 0
sign.1 [sign(-inf)] -1
sign.2 [sign(+inf)] 1
sign.3 [sign(undf)] undf
sign.4 [sign(0)] 0
sin.1 [sin(-inf)] undf
sin.2 [sin(+inf)] undf
sin.3 [sin(undf)] undf
sin.4 [sin(0)] 0
sqr.1 [sqr(-inf)] inf
sqr.2 [sqr(+inf)] inf
sqr.3 [sqr(undf)] undf
sqr.4 [sqr(0)] 0
sqrt.1 [sqrt(-inf)] undf
sqrt.2 [sqrt(+inf)] inf
sqrt.3 [sqrt(undf)] undf
sqrt.4 [sqrt(0)] 0
sqrt.5 [sqrt(-1)] undf
tan.1 [tan(-inf)] undf
tan.2 [tan(+inf)] undf
tan.3 [tan(undf)] undf
tan.4 [tan(0)] 0
trunc.1 [trunc(-inf)] -inf
trunc.2 [trunc(+inf)] inf
trunc.3 [trunc(undf)] undf
trunc.4 [trunc(55.55)] 55
trunc.5 [trunc(-55.55)] -55
Parameters
diff(f,c,v) differences
delta(f,c) 'calculated - expected'
;
sets
fc(f,c) differences
cc(c) 'fact values to tune up' / 5 * 15 /
;
scalars t, i;
t = res('fact','9','expected');
for {i = 21 to 30,
t = t * i;
};
res('fact','10','expected') = t;
for {i = 31 to 60,
t = t * i;
};
res('fact','11','expected') = t;
for {i = 61 to 90,
t = t * i;
};
res('fact','12','expected') = t;
for {i = 91 to 120,
t = t * i;
};
res('fact','13','expected') = t;
for {i = 121 to 150,
t = t * i;
};
res('fact','14','expected') = t;
for {i = 151 to 166,
t = t * i;
};
res('fact','15','expected') = t;
* patch up small relative errors in fact: our computation of expected
* values in this test will not be 100% precise
fc('fact',cc) = yes;
delta(fc) = abs(res(fc,'calculated') - res(fc,'expected')) / res(fc,'expected');
fc(f,c) = fc(f,c) and [delta(f,c) < 1e-15];
res(fc,'expected') = res(fc,'calculated');
fc(f,c) = no;
display delta;
delta(f,c) = 0;
fc(f,c) = res(f,c,'calculated') <> res(f,c,'expected');
diff(fc,v) = res(fc,v);
delta(fc) = res(fc,'calculated') - res(fc,'expected');
display diff, delta;
abort$card(diff) 'results do not match';
```