Scaled.mesa
Copyright Ó 1985, 1986, 1987, 1988, 1991 by Xerox Corporation. All rights reserved.
Created February 4, 1983
Edited by Michael Plass, August 27, 1991 10:29 am PDT
Doug Wyatt, January 19, 1987 7:44:39 pm PST
DIRECTORY Basics;
Scaled: CEDAR DEFINITIONS
= BEGIN
Value: TYPE = Basics.LongNumber.pair;
zero: Value = [pair[0, 0]];
one: Value = [pair[hi: 1, lo: 0]];
unit: Value = one;
epsilon: Value = [pair[hi: 0, lo: 1]];
oneMinusEpsilon: Value = [pair[hi: 0, lo: LAST[CARD16]]];
half: Value = [pair[hi: 0, lo: (LAST[CARD16]/2)+1]];
infinity: Value = LOOPHOLE[LAST[INT]];
negInfinity: Value = LOOPHOLE[FIRST[INT]];
IntRep: PROC [v: Value] RETURNS [INT] = INLINE { RETURN[LOOPHOLE[v]] };
ValRep: PROC [i: INT] RETURNS [Value] = INLINE { RETURN[LOOPHOLE[i]] };
FromInt: PROC [int: INTEGER] RETURNS [Value]
= INLINE { RETURN[[pair[hi: LOOPHOLE[int], lo: 0]]] };
FromReal: PROC [real: REAL] RETURNS [Value];
PLUS: PROC [a, b: Value] RETURNS [Value]
= INLINE { RETURN[ValRep[IntRep[a] + IntRep[b]]] };
MINUS: PROC [a, b: Value] RETURNS [Value]
= INLINE { RETURN[ValRep[IntRep[a] - IntRep[b]]] };
UMINUS: PROC [a: Value] RETURNS [Value]
= INLINE { RETURN[ValRep[-IntRep[a]]] };
TIMES: PROC [a, b: Value] RETURNS [Value];
DIVIDE: PROC [a, b: Value] RETURNS [Value];
GREATER: PROC [a, b: Value] RETURNS [BOOL]
= INLINE { RETURN[IntRep[a] > IntRep[b]] };
LESS: PROC [a, b: Value] RETURNS [BOOL]
= INLINE { RETURN[IntRep[a] < IntRep[b]] };
Max: PROC [a, b: Value] RETURNS [Value]
= INLINE { RETURN[ValRep[MAX[IntRep[a], IntRep[b]]]] };
Min: PROC [a, b: Value] RETURNS [Value]
= INLINE { RETURN[ValRep[MIN[IntRep[a], IntRep[b]]]] };
Floor: PROC [a: Value] RETURNS [INT16]
= INLINE { RETURN[LOOPHOLE[a.hi]] };
Ceiling: PROC [a: Value] RETURNS [INT16]
= INLINE { RETURN[Floor[PLUS[a, oneMinusEpsilon]]] };
Round: PROC [a: Value] RETURNS [INT16]
= INLINE { RETURN[Floor[PLUS[a, half]]] };
Float: PROC [a: Value] RETURNS [REAL];
Scale: PROC [a: Value, scale: INTEGER] RETURNS [Value];
Halve: PROC [a: Value] RETURNS [Value];
END.