$TITLE EXAMPLES OF EXTENDED ARITHMETIC  (CRAZY,SEQ=67)
*  THIS EXAMPLE PROGRAM TESTS AND DEMONSTRATES THE DEFINITION OF SPECIAL
*  (CRAZY) VALUES. ALL GAMS OPERATIONS ARE DEFINED OVER THE CLOSED
*  INTERVAL FROM -INFINITY (-INF) TO +INFINITY (INF) AND THE THREE OTHER
*  SPECIAL VALUES: EPSILON (EPS), MISSING (NA) AND UNDEFINED (UNDF).
*
*  REFERENCE: BROOKE A, KENDRICK D AND MEERAUS A, GAMS: A USER'S GUIDE,
*             THE SCIENTIFIC PRESS, REDWOOD CITY, CALIFORNIA, 1988.

* NOTICE THAT ANY CHARACTERS ARE LEGAL IN A "QUOTED" LABEL

SET OP1 / MINUS-INF, "-4.000", ZERO, "+2.500", PLUS-INF, EPSILON, MISSING
          UNDEFINED /;  ALIAS(OP1,OP2);

* THE VALUE UNDF CAN NOT BE ENTERED, ONLY PRODUCED BY AN ILLEGAL 
* OPERATION, AS IS SHOWN BELOW

PARAMETER A(OP1) / MINUS-INF -INF, "-4.000" -4, ZERO     0, "+2.500" 2.5
                   PLUS-INF  +INF, EPSILON  EPS, MISSING NA   /;

          A("UNDEFINED") = 0/0; DISPLAY A;

PARAMETERS

B(OP1,OP2) "OPERAND 1 PLUS OPERAND 2: O1 + O2"
C(OP1,OP2) "OPERAND 1 MINUS OPERAND 2: O1 - O2"
D(OP1,OP2) "OPERAND 1 TO THE POWER OPERAND 2: O1 ** O2 (O2 IS  REAL)"
E(OP1,OP2) "OPERAND 1 TIMES OPERAND 2: O1 * O2"
F(OP1,OP2) "OPERAND 1 DIVIDED BY OPERAND 2: O1 / O2"
G(OP1,OP2) "OPERAND 1 EQ OPERAND 2: O1 EQ O2"
H(OP1,OP2) "OPERAND 1 LE OPERAND 2: O1 LE O2"
I(OP1,OP2) "OPERAND 1 GE OPERAND 2: O1 GE O2"
J(OP1,OP2) "OPERAND 1 NE OPERAND 2: O1 NE O2"
K(OP1,OP2) "OPERAND 1 LT OPERAND 2: O1 LT O2"
L(OP1,OP2) "OPERAND 1 GT OPERAND 2: O1 GT O2"
M(OP1,OP2) "OPERAND 1 OR OPERAND 2: O1 OR O2"
N(OP1,OP2) "OPERAND 1 AND OPERAND 2: O1 AND O2"
O(OP1,OP2) "OPERAND 1 XOR OPERAND 2: O1 XOR O2"
P(OP1,OP2) "OPERAND 1 TO THE POWER OPERAND 2: O1 ** O2  (O2 IS INTEGER)"
Q(OP1,OP2) "MAXIMUM OF OPERAND 1, OPERAND 2: MAX(O1,O2)"
R(OP1,OP2) "MINIMUM OF OPERAND 1, OPERAND 2: MIN(O1,O2)"
R1(OP1,OP2)"NORMAL RANDOM NUMBER WITH MEAN O1 AND STD O2: NORMAL(O1,O2)"
S(OP1,OP2) "MOD OF OPERAND 1, OPERAND 2: MOD(O1,O2)"
T(OP1,OP2) "ROUND ARGUMENT 1 BY ARGUMENT 2 PLACES: ROUND(O1,O2)"
T1(OP1,OP2)"UNIFORM RANDOM NUMBER BETWEEN O1 AND O2: UNIFORM(O1,O2)"
U(OP1,OP2) "DOLLAR CONTROL ON RIGHT HAND SIDE: U = O1$O2"
V(OP1,OP2) "DOLLAR CONTROL ON LEFT HAND SIDE: V$O2 = O1"

 AA(*,OP1)  SINGLE ARGUMENT FUNCTIONS;

 SCALAR  LOOPTEST  TESTS $-CONTROL ON LOOPS
         SUMTEST   TEST $-CONTROL ON SUM OPERATIONS
         SUMT      SUM TEST
         PROT      PROD TEST
         MINT      SMIN TEST
         MAXT      SMAX TEST;

 B(OP1,OP2) = A(OP1) + A(OP2);
 C(OP1,OP2) = A(OP1) - A(OP2);
 D(OP1,OP2) = A(OP1)**A(OP2);
 P(OP1,OP2) = POWER(A(OP1),A(OP2));
 E(OP1,OP2) = A(OP1)*A(OP2);
 F(OP1,OP2) = A(OP1)/A(OP2);
 G(OP1,OP2) = A(OP1) EQ A(OP2);
 H(OP1,OP2) = A(OP1) LE A(OP2);
 I(OP1,OP2) = A(OP1) GE A(OP2);
 J(OP1,OP2) = A(OP1) NE A(OP2);
 K(OP1,OP2) = A(OP1) LT A(OP2);
 L(OP1,OP2) = A(OP1) GT A(OP2);
 M(OP1,OP2) = A(OP1) OR A(OP2);
 N(OP1,OP2) = A(OP1) AND A(OP2);
 O(OP1,OP2) = A(OP1) XOR A(OP2);
 Q(OP1,OP2) = MAX(A(OP1),A(OP2));
 R(OP1,OP2) = MIN(A(OP1),A(OP2));
 R1(OP1,OP2)= NORMAL(A(OP1),A(OP2));
 S(OP1,OP2) = MOD(A(OP1),A(OP2));
 T(OP1,OP2) = ROUND(A(OP1),A(OP2));
 T1(OP1,OP2)= UNIFORM(A(OP1),A(OP2));
 U(OP1,OP2) = A(OP1)$A(OP2);
 V(OP1,OP2)$A(OP2) = A(OP1);

 AA("ABSOLUTE",  OP1) = ABS   (A(OP1));
 AA("ARCTAN",    OP1) = ARCTAN(A(OP1));
 AA("CEILING",   OP1) = CEIL  (A(OP1));
 AA("COS",       OP1) = COS   (A(OP1));
 AA("FLOOR",     OP1) = FLOOR (A(OP1));
 AA("ERRORF",    OP1) = ERRORF(A(OP1));
 AA("EXPONENT",  OP1) = EXP   (A(OP1));
 AA("LOGE",      OP1) = LOG   (A(OP1));
 AA("LOG10",     OP1) = LOG10 (A(OP1));
 AA("SINE",      OP1) = SIN   (A(OP1));
 AA("SIGN",      OP1) = SIGN  (A(OP1));
 AA("SQUAREROOT",OP1) = SQRT  (A(OP1));
 AA("SQUARE",    OP1) = SQR   (A(OP1));
 AA("MAPVAL",    OP1) = MAPVAL(A(OP1));
 AA("TRUNCATE",  OP1) = TRUNC (A(OP1));
 AA("NOT",       OP1) = NOT    A(OP1);

 DISPLAY A,B,C,E,F,G,H,I,J,K,L,M,N,O,D,P,Q,R,R1,S,T,T1,U,V,AA;

 LOOPTEST = 0; LOOP(OP1$A(OP1), LOOPTEST = LOOPTEST + 10**(ORD(OP1)-1) );
 SUMTEST = SUM(OP1$A(OP1), 10**(ORD(OP1)-1));
 SUMT = SUM(OP1, A(OP1));  PROT = PROD(OP1, A(OP1));
 MINT = SMIN(OP1, A(OP1)); MAXT = SMAX(OP1, A(OP1));

OPTION DECIMALS=0; DISPLAY LOOPTEST, SUMTEST, SUMT, PROT, MINT, MAXT;
