ifstat5.gms : Tests $if/$ifI/$ifE statements

Description

Tests compile-time if tests, especially the new $ifE test

For ife  expr1 == expr2   true if (expr1-expr2)/(1+abs(expr2)) < 1e-12
For ife  expr1            true if expr1 <> 0

Contributor: Alex Meeraus


Small Model of Type : GAMS


Category : GAMS Test library


Main file : ifstat5.gms

$title 'Tests $if/$ifI/$ifE statements' (IFSTAT5,SEQ=325)

$onText
Tests compile-time if tests, especially the new $ifE test

For ife  expr1 == expr2   true if (expr1-expr2)/(1+abs(expr2)) < 1e-12
For ife  expr1            true if expr1 <> 0

Contributor: Alex Meeraus
$offText

$onDollar

$if NOT ''  $abort line %system.line%
$if NOT ""  $abort line %system.line%
$if     'x' $abort line %system.line%

$if NOT '1111' == '1111' $abort line %system.line%
$if NOT  '1111'== "1111" $abort line %system.line%
$if NOT "1111" =='1111'  $abort line %system.line%
$if NOT  '1111'=='1111'  $abort line %system.line%

$if NOT  1111  == 1111   $abort line %system.line%
$if NOT    1111== 1111   $abort line %system.line%
$if NOT  1111  ==1111    $abort line %system.line%
$if NOT    1111==1111    $abort line %system.line%

$if NOT  1111  == '1111' $abort line %system.line%
$if NOT    1111== '1111' $abort line %system.line%
$if NOT  1111  =='1111'  $abort line %system.line%
$if NOT    1111=='1111'  $abort line %system.line%

$if NOT  '1111'== 1111   $abort line %system.line%
$if NOT  '1111'== 1111   $abort line %system.line%
$if NOT '1111' ==1111    $abort line %system.line%
$if NOT  '1111'==1111    $abort line %system.line%

$if      'aaaa' == 'AAAA' $abort line %system.line%
$ifI NOT 'aaaa' == 'AAAA' $abort line %system.line%

$ifE NOT 001 == 1 $abort line %system.line%
$if      001 == 1 $abort line %system.line%

$ifE 2>3  == 1 $abort line %system.line%
$ifE 2>=3 == 1 $abort line %system.line%
$ifE 2<>3 == 0 $abort line %system.line%
$ifE 2=3  == 1 $abort line %system.line%
$ifE 2<3  == 0 $abort line %system.line%
$ifE 2<=3 == 0 $abort line %system.line%

$ifE '2 GT 3' == 1 $abort line %system.line%
$ifE '2 GE 3' == 1 $abort line %system.line%
$ifE '2 NE 3' == 0 $abort line %system.line%
$ifE '2 EQ 3' == 1 $abort line %system.line%
$ifE '2 LT 3' == 0 $abort line %system.line%
$ifE '2 LE 3' == 0 $abort line %system.line%

$ifE 2>2  == 1 $abort line %system.line%
$ifE 2>=2 == 0 $abort line %system.line%
$ifE 2<>2 == 1 $abort line %system.line%
$ifE 2=2  == 0 $abort line %system.line%
$ifE 2<2  == 1 $abort line %system.line%
$ifE 2<=2 == 0 $abort line %system.line%

$ifE '2 GT 2' == 1 $abort line %system.line%
$ifE '2 GE 2' == 0 $abort line %system.line%
$ifE '2 NE 2' == 1 $abort line %system.line%
$ifE '2 EQ 2' == 0 $abort line %system.line%
$ifE '2 LT 2' == 1 $abort line %system.line%
$ifE '2 LE 2' == 0 $abort line %system.line%

$ifE NOT 4/2 == 2   $abort line %system.line%
$ifE NOT 3/2 == 1.5 $abort line %system.line%
$ifE NOT 3*2 == 6   $abort line %system.line%
$ifE NOT 3+2 == 5   $abort line %system.line%
$ifE NOT 3-2 == 1   $abort line %system.line%
$ifE NOT 2^3 == 8   $abort line %system.line%
$ifE NOT 3-2 == 1   $abort line %system.line%

$ifE NOT log2(16)^2        == 16   $abort line %system.line%
$ifE NOT sqr(log2(16))     == 16   $abort line %system.line%
$ifE NOT power(log2(16),2) == 16   $abort line %system.line%
$ifE NOT exp(log(16))      == 16   $abort line %system.line%
$ifE NOT 10**log10(16)     == 16   $abort line %system.line%

$ifE NOT round(123.456)    == 123     $abort line %system.line%
$ifE NOT round(123.456,0)  == 123     $abort line %system.line%
$ifE NOT round(123.456,1)  == 123.5   $abort line %system.line%
$ifE NOT round(123.456,2)  == 123.46  $abort line %system.line%
$ifE NOT round(123.456,3)  == 123.456 $abort line %system.line%
$ifE NOT round(123.456,5)  == 123.456 $abort line %system.line%
$ifE NOT round(123.456,-1) == 120     $abort line %system.line%
$ifE NOT round(123.456,-2) == 100     $abort line %system.line%
$ifE NOT round(123.456,-3) ==   0     $abort line %system.line%

$ifE NOT ifthen(1+1,2,3) == 2   $abort line %system.line%
$ifE NOT ifthen(1-1,2,3) == 3   $abort line %system.line%

$ifE NOT max(-1,+1) ==  1  $abort line %system.line%
$ifE NOT min(-1,+1) == -1  $abort line %system.line%
$ifE NOT min(-1,+1,3,max(1,2,3,40),3) == -1  $abort line %system.line%

$ifE NOT sqr(sin(.5))+sqr(cos(.5)) == 1 $abort line %system.line%
$ifE     sqr(sin(.5))+sqr(cos(.5))-1    $abort line %system.line%
$ifE     0                              $abort line %system.line%
$ifE NOT 1e-300                         $abort line %system.line%
$ifE     1e-300=0                       $abort line %system.line%
$ifE     '   1e-300   =  0   '          $abort line %system.line%
$ifE NOT 1e-300 == 0                    $abort line %system.line%
$ifE NOT '1e-300'==0                    $abort line %system.line%