$Eval

Top  Previous  Next

This evaluates a numerical expression at compile time and places it into a scoped control variable.  In turn one can use $ife to do numeric testing on the value of this variable.

 

The format is

 $Eval expression

 

The expression must consist of constants, functions or other control variables with numerical values. The following GAMS date and release functions may also be used: jdate, jtime, gyear, gmonth, gday, gdow, gleap, ghour, gminute, gsecond, gmillisec, jstart, jnow, gamsversion, and gamsrelease

Example:

 $set znumber 4

 $Eval anumber %znumber%+10

 $ife %anumber%>14 display "it exceeds 14" "%anumber%"

 $ife %anumber%<14 display "it is less than 14" "%anumber%"

 $ife %anumber%=14 display "it equals 14" "%anumber%"

 $ife %anumber%<>14 display "it does not equal 14" "%anumber%"

Notes:

Related functions are

         $EvalLocal                that works with local control variables

         $EvalGlobal        that works with global control variables

Unfortunately GAMS allows one to define scoped local and global variables with the same name but treats them as different under some cases and prioritizes them when using $ife or $if as discussed here.
The calculations can only involve real numbers
Expression evaluation proceeds from left to right
When items are not set off in parentheses the operator precedence is:

OR XOR EQV IMP

AND

NOT

< <= = <> >= > LE LE EQ NE GE GT

+ - binary and unary

* /

^ **

The following functions can be used in expressions:

abs ceil cos errorlevel exp fact floor frac gamsrelease gamsversion gday gdow ghour gleap gmillisec gminute gmonth gsecond gyear IfThen jdate jnow jobhandle jobkill jobstatus jobterminate jstart jtime log log2 log10 max min mod PI power round sign sin sleep sqr sqrt tan trunc