-- file IeeeFloat.mesa
-- Last modified by Satterthwaite, May 31, 1982 12:02 pm
-- adaptation of Real.mesa+Ieee.mesa for compiler use

Real: DEFINITIONS = {

 -- extended format
 
  NumberType: TYPE = {normal, zero, infinity, nan};

  Extended: TYPE = RECORD [
    type: NumberType,
    sign: BOOL,
    exp: INTEGER,
    frac: LONG CARDINAL];

 -- modes

  RoundingMode: TYPE = {rn, rz, rm, rp};
    -- rn: Round to nearest (unbiased)
    -- rz: Round to zero (truncate)
    -- rp: Round to plus infinity (round up)
    -- rm: Round to minus infinity (round down)

  NormalizationMode: TYPE = {warning, normalizing};

  Mode: TYPE = RECORD [
    nm: NormalizationMode ← warning,
    round: RoundingMode ← rn];

 -- Constants

  PlusZero: REAL = LOOPHOLE[LONG[00000000000b]];
  MinusZero: REAL = LOOPHOLE[20000000000b];
  PlusInfinity: REAL = LOOPHOLE[17740000000b];
  MinusInfinity: REAL = LOOPHOLE[37740000000b];
 
  TrapNonTrappingNaN: LONG CARDINAL = LONG[1];
  TrapTrappingNaN: LONG CARDINAL = LONG[2];
  
 -- Exceptions

  Flag: TYPE = BOOL ← FALSE;
  Exception: TYPE = {
    fixOverflow, inexactResult, invalidOperation, divisionByZero, overflow, underflow};
  ExceptionFlags: TYPE = PACKED ARRAY Exception OF Flag;

  NoExceptions: ExceptionFlags = ALL[FALSE];

 -- Operations

  RealException: SIGNAL [flags: ExceptionFlags];

  RealToExtended: PROC [a: REAL] RETURNS [Extended];
  ExtendedToReal: PROC [e: Extended] RETURNS [REAL];
  
  Abs: PROC [a: REAL] RETURNS [REAL];
  Negate: PROC [a: REAL] RETURNS [REAL];
  PairToReal: PROC [fr: LONG INTEGER, exp10: INTEGER] RETURNS [REAL];

  }.