$EvalGlobal

Top  Previous  Next

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

 

The format is

 $EvalGlobal expression

 

The expression must consist of constants, functions or other control variables with numerical values.

Example:

 $set znumber 4

       $Evalglobal 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

         $Eval                        that works with scoped control variables

         $Evallocal                that works with local 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  exp   floor  frac  IfThen  log   log2  log10  max

min  mod   PI   power round  sign  sin     sleep sqr   sqrt   tan   trunk