-- version control marker $Id: cgtest66.occ,v 1.3 1995/10/11 10:21:29 djb1 Exp $

PROC cgtest66 (CHAN OF BYTE keyb, scr, err)
  #INCLUDE "cgmain.occ"
  #INCLUDE "cgreal.occ"

  INT dummy :
  VAL []BYTE b.dummy RETYPES dummy :
  VAL bpw IS SIZE b.dummy :
  SEQ
    init ("CG test 66", "BYTE arithmetic, and conversions")
    --{{{  test BYTE arith
    PROC test.BYTE.arith()
      VAL cb1 IS 10(BYTE) :
      VAL cb2 IS  6(BYTE) :
      VAL cb3 IS 30(BYTE) :
      BYTE b1, b2, b3, b4, pb, nb :
      BOOL bool :
      INT i :
      VAL ci IS 3 :
      SEQ
        title("BYTE arithmetic")
        --{{{  init
        b1 := id.BYTE(10)
        b2 := id.BYTE(6)
        i := id(3)
        pb := id.BYTE(MOSTPOS BYTE)
        nb := id.BYTE(MOSTNEG BYTE)
        --}}}
        --{{{  dyadics
        --{{{  +
        b3 := b1 + b2
        check.BYTE(b3, 16, "BY-000")
        b3 := b1 + cb2
        check.BYTE(b3, 16, "BY-001")
        b3 := cb1 + b2
        check.BYTE(b3, 16, "BY-002")
        b3 := cb1 + cb2
        check.BYTE(b3, 16, "BY-003")
        
        --}}}
        --{{{  -
        b3 := b1 - b2
        check.BYTE(b3, 4, "BY-010")
        b3 := b1 - cb2
        check.BYTE(b3, 4, "BY-011")
        b3 := cb1 - b2
        check.BYTE(b3, 4, "BY-012")
        b3 := cb1 - cb2
        check.BYTE(b3, 4, "BY-013")
        
        --}}}
        --{{{  *
        b3 := b1 * b2
        check.BYTE(b3, 60, "BY-020")
        b3 := b1 * cb2
        check.BYTE(b3, 60, "BY-021")
        b3 := cb1 * b2
        check.BYTE(b3, 60, "BY-022")
        b3 := cb1 * cb2
        check.BYTE(b3, 60, "BY-023")
        
        --}}}
        --{{{  /
        b3 := b1 / b2
        check.BYTE(b3, 1, "BY-030")
        b3 := b1 / cb2
        check.BYTE(b3, 1, "BY-031")
        b3 := cb1 / b2
        check.BYTE(b3, 1, "BY-032")
        b3 := cb1 / cb2
        check.BYTE(b3, 1, "BY-033")
        
        --}}}
        --{{{  \
        b3 := b1 \ b2
        check.BYTE(b3, 4, "BY-040")
        b3 := b1 \ cb2
        check.BYTE(b3, 4, "BY-041")
        b3 := cb1 \ b2
        check.BYTE(b3, 4, "BY-042")
        b3 := cb1 \ cb2
        check.BYTE(b3, 4, "BY-043")
        
        --}}}
        --{{{  PLUS
        b3 := b1 PLUS b2
        check.BYTE(b3, 16, "BY-050")
        b3 := b1 PLUS cb2
        check.BYTE(b3, 16, "BY-051")
        b3 := cb1 PLUS b2
        check.BYTE(b3, 16, "BY-052")
        b3 := cb1 PLUS cb2
        check.BYTE(b3, 16, "BY-053")
        
        b3 := pb PLUS b1
        check.BYTE(b3, (MOSTNEG BYTE) + (cb1 - 1), "BY-054")
        b3 := pb PLUS cb1
        check.BYTE(b3, (MOSTNEG BYTE) + (cb1 - 1), "BY-055")
        b3 := (MOSTPOS BYTE) PLUS b1
        check.BYTE(b3, (MOSTNEG BYTE) + (cb1 - 1), "BY-056")
        b3 := (MOSTPOS BYTE) PLUS cb1
        check.BYTE(b3, (MOSTNEG BYTE) + (cb1 - 1), "BY-057")
        
        --}}}
        --{{{  MINUS
        b3 := b1 MINUS b2
        check.BYTE(b3, 4, "BY-060")
        b3 := b1 MINUS cb2
        check.BYTE(b3, 4, "BY-061")
        b3 := cb1 MINUS b2
        check.BYTE(b3, 4, "BY-062")
        b3 := cb1 MINUS cb2
        check.BYTE(b3, 4, "BY-063")
        
        b3 := nb MINUS b1
        check.BYTE(b3, (MOSTPOS BYTE) - (cb1 - 1), "BY-064")
        b3 := nb MINUS cb1
        check.BYTE(b3, (MOSTPOS BYTE) - (cb1 - 1), "BY-065")
        b3 := (MOSTNEG BYTE) MINUS b1
        check.BYTE(b3, (MOSTPOS BYTE) - (cb1 - 1), "BY-066")
        b3 := (MOSTNEG BYTE) MINUS cb1
        check.BYTE(b3, (MOSTPOS BYTE) - (cb1 - 1), "BY-067")
        
        --}}}
        --{{{  TIMES
        b3 := b1 TIMES b2
        check.BYTE(b3, 60, "BY-070")
        b3 := b1 TIMES cb2
        check.BYTE(b3, 60, "BY-071")
        b3 := cb1 TIMES b2
        check.BYTE(b3, 60, "BY-072")
        b3 := cb1 TIMES cb2
        check.BYTE(b3, 60, "BY-073")
        
        b3 := id.BYTE(cb3)
        b4 := b1 TIMES b3
        check.BYTE(b4, 44, "BY-074")
        b4 := b1 TIMES cb3
        check.BYTE(b4, 44, "BY-075")
        b4 := cb1 TIMES b3
        check.BYTE(b4, 44, "BY-076")
        b4 := cb1 TIMES cb3
        check.BYTE(b4, 44, "BY-077")
        
        --}}}
        --{{{  \/
        b3 := b1 \/ b2
        check.BYTE(b3, 14, "BY-080")
        b3 := b1 \/ cb2
        check.BYTE(b3, 14, "BY-081")
        b3 := cb1 \/ b2
        check.BYTE(b3, 14, "BY-082")
        b3 := cb1 \/ cb2
        check.BYTE(b3, 14, "BY-083")
        
        --}}}
        --{{{  /\
        b3 := b1 /\ b2
        check.BYTE(b3, 2, "BY-090")
        b3 := b1 /\ cb2
        check.BYTE(b3, 2, "BY-091")
        b3 := cb1 /\ b2
        check.BYTE(b3, 2, "BY-092")
        b3 := cb1 /\ cb2
        check.BYTE(b3, 2, "BY-093")
        
        --}}}
        --{{{  ><
        b3 := b1 >< b2
        check.BYTE(b3, 12, "BY-100")
        b3 := b1 >< cb2
        check.BYTE(b3, 12, "BY-101")
        b3 := cb1 >< b2
        check.BYTE(b3, 12, "BY-102")
        b3 := cb1 >< cb2
        check.BYTE(b3, 12, "BY-103")
        
        --}}}
        --{{{  AFTER
        bool := b1 AFTER b2
        check.BOOL(bool, TRUE, "BY-110")
        bool := b1 AFTER cb2
        check.BOOL(bool, TRUE, "BY-111")
        bool := cb1 AFTER b2
        check.BOOL(bool, TRUE, "BY-112")
        bool := cb1 AFTER cb2
        check.BOOL(bool, TRUE, "BY-113")
        
        bool := b2 AFTER b1
        check.BOOL(bool, FALSE, "BY-114")
        bool := b2 AFTER cb1
        check.BOOL(bool, FALSE, "BY-115")
        bool := cb2 AFTER b1
        check.BOOL(bool, FALSE, "BY-116")
        bool := cb2 AFTER cb1
        check.BOOL(bool, FALSE, "BY-117")
        
        bool := b1 AFTER b1
        check.BOOL(bool, FALSE, "BY-118")
        bool := cb1 AFTER cb1
        check.BOOL(bool, FALSE, "BY-119")
        
        --}}}
        --{{{  >>
        b3 := b1 >> i
        check.BYTE(b3, 1, "BY-120")
        b3 := b1 >> ci
        check.BYTE(b3, 1, "BY-121")
        b3 := cb1 >> i
        check.BYTE(b3, 1, "BY-122")
        b3 := cb1 >> ci
        check.BYTE(b3, 1, "BY-123")
        
        --}}}
        --{{{  <<
        b3 := b1 << i
        check.BYTE(b3, 80, "BY-130")
        b3 := b1 << ci
        check.BYTE(b3, 80, "BY-131")
        b3 := cb1 << i
        check.BYTE(b3, 80, "BY-132")
        b3 := cb1 << ci
        check.BYTE(b3, 80, "BY-133")
        
        --}}}
        
        --}}}
        --{{{  monadics
        --{{{  unary MINUS
        b3 := MINUS b1
        check.BYTE(b3, (MOSTPOS BYTE) - (cb1 - 1), "BY-200")
        b3 := MINUS cb1
        check.BYTE(b3, (MOSTPOS BYTE) - (cb1 - 1), "BY-201")
        b3 := MINUS pb
        check.BYTE(b3, 1, "BY-202")
        b3 := MINUS (MOSTPOS BYTE)
        check.BYTE(b3, 1, "BY-203")
        b3 := MINUS nb
        check.BYTE(b3, 0, "BY-204")
        b3 := MINUS (MOSTNEG BYTE)
        check.BYTE(b3, 0, "BY-205")
        
        --}}}
        --{{{  BITNOT
        b3 := ~ b1
        check.BYTE(b3, (MOSTPOS BYTE) - cb1, "BY-210")
        b3 := ~ cb1
        check.BYTE(b3, (MOSTPOS BYTE) - cb1, "BY-211")
        b3 := ~ pb
        check.BYTE(b3, 0, "BY-212")
        b3 := ~ (MOSTPOS BYTE)
        check.BYTE(b3, 0, "BY-213")
        b3 := ~ nb
        check.BYTE(b3, MOSTPOS BYTE, "BY-214")
        b3 := ~ (MOSTNEG BYTE)
        check.BYTE(b3, MOSTPOS BYTE, "BY-215")
        
        --}}}
        
        --}}}
    :
    test.BYTE.arith()
    --}}}
    --{{{  conversions to/from real
    PROC conversions.to.from.real()
      SEQ
        title("Conversions to/from REAL")
        --{{{  BYTE <=> REAL32
        VAL title.str IS "BYTE <=> REAL32" :
        
        DATA TYPE int.type  IS BYTE :
        DATA TYPE real.type IS REAL32 :
        
        int.type FUNCTION id.int.type(VAL int.type x) IS
                 int.type id.BYTE(BYTE x) :
        real.type FUNCTION id.real.type(VAL real.type x) IS
                  real.type ROUND id.REAL32(REAL32 ROUND x) :
        
        PROC check.real.type(VAL real.type x, y, VAL []BYTE msg)
          check.REAL32(REAL32 ROUND x, REAL32 ROUND y, msg)
        :
        PROC check.int.type(VAL int.type x, y, VAL []BYTE msg)
          check.BYTE(BYTE x, BYTE y, msg)
        :
        
        --}}}
        #INCLUDE "cg66cnvt.occ"
        --{{{  BYTE <=> REAL64
        VAL title.str IS "BYTE <=> REAL64" :
        
        DATA TYPE int.type  IS BYTE :
        DATA TYPE real.type IS REAL64 :
        
        int.type FUNCTION id.int.type(VAL int.type x) IS
                 int.type id.BYTE(BYTE x) :
        real.type FUNCTION id.real.type(VAL real.type x) IS
                  real.type ROUND id.REAL64(REAL64 ROUND x) :
        
        PROC check.real.type(VAL real.type x, y, VAL []BYTE msg)
          check.REAL64(REAL64 ROUND x, REAL64 ROUND y, msg)
        :
        PROC check.int.type(VAL int.type x, y, VAL []BYTE msg)
          check.BYTE(BYTE x, BYTE y, msg)
        :
        
        --}}}
        #INCLUDE "cg66cnvt.occ"
        --{{{  INT16 <=> REAL32
        VAL title.str IS "INT16 <=> REAL32" :
        
        DATA TYPE int.type  IS INT16 :
        DATA TYPE real.type IS REAL32 :
        
        int.type FUNCTION id.int.type(VAL int.type x) IS
                 int.type id.INT16(INT16 x) :
        real.type FUNCTION id.real.type(VAL real.type x) IS
                  real.type ROUND id.REAL32(REAL32 ROUND x) :
        
        PROC check.real.type(VAL real.type x, y, VAL []BYTE msg)
          check.REAL32(REAL32 ROUND x, REAL32 ROUND y, msg)
        :
        PROC check.int.type(VAL int.type x, y, VAL []BYTE msg)
          check.INT16(INT16 x, INT16 y, msg)
        :
        
        --}}}
        #INCLUDE "cg66cnvt.occ"
        --{{{  INT16 <=> REAL64
        VAL title.str IS "INT16 <=> REAL64" :
        
        DATA TYPE int.type  IS INT16 :
        DATA TYPE real.type IS REAL64 :
        
        int.type FUNCTION id.int.type(VAL int.type x) IS
                 int.type id.INT16(INT16 x) :
        real.type FUNCTION id.real.type(VAL real.type x) IS
                  real.type ROUND id.REAL64(REAL64 ROUND x) :
        
        PROC check.real.type(VAL real.type x, y, VAL []BYTE msg)
          check.REAL64(REAL64 ROUND x, REAL64 ROUND y, msg)
        :
        PROC check.int.type(VAL int.type x, y, VAL []BYTE msg)
          check.INT16(INT16 x, INT16 y, msg)
        :
        
        --}}}
        #INCLUDE "cg66cnvt.occ"
    :
    conversions.to.from.real()
    --}}}
    finish ()
:
