ImagerScaled.mesa
Copyright Ó 1990, 1991 by Xerox Corporation. All rights reserved.
This is a bug-reduced version of Scaled.mesa, which exhibits some porting bugs.
Michael Plass, December 28, 1990 11:42 am PST
DIRECTORY Basics, Scaled;
ImagerScaled: CEDAR DEFINITIONS IMPORTS Scaled
= 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]
= INLINE { RETURN [Scaled.FromReal[real]] };
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]]] };
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]
= INLINE { RETURN [Scaled.Float[a]] };
END.