Scaled.mesa
Copyright © 1985 by Xerox Corporation. All rights reserved.
Created February 4, 1983
Edited by Michael Plass, November 15, 1983 9:59 am
Doug Wyatt, March 7, 1985 5:12:27 pm PST
DIRECTORY
Basics USING [bitsPerWord, DoubleShiftRight],
Real USING [FScale, RoundLI];
Scaled: CEDAR DEFINITIONS
IMPORTS Basics, Real
= BEGIN
Value:
TYPE =
MACHINE
DEPENDENT
RECORD [fraction:
CARDINAL ← 0, integerPart:
INTEGER];
one: Value = [integerPart: 1, fraction: 0];
epsilon: Value = [integerPart: 0, fraction: 1];
oneMinusEpsilon: Value = [integerPart: 0, fraction:
LAST[
CARDINAL]];
half: Value = [integerPart: 0, fraction:
LOOPHOLE[
FIRST[
INTEGER]]];
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[[integerPart: int, fraction: 0]] };
FromReal:
PROC [real:
REAL]
RETURNS [Value]
= INLINE { RETURN[ValRep[Real.RoundLI[Real.FScale[real, Basics.bitsPerWord]]]] };
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 [
INTEGER]
= INLINE { RETURN[a.integerPart] };
Ceiling:
PROC [a: Value]
RETURNS [
INTEGER]
= INLINE { RETURN[Floor[PLUS[a, oneMinusEpsilon]]] };
Round:
PROC [a: Value]
RETURNS [
INTEGER]
= INLINE { RETURN[Floor[PLUS[a, half]]] };
Float:
PROC [a: Value]
RETURNS [
REAL]
= INLINE { RETURN[Real.FScale[IntRep[a], -Basics.bitsPerWord]] };
Scale:
PROC [a: Value, scale:
INTEGER]
RETURNS [Value];
Halve:
PROC [a: Value]
RETURNS [Value]
= INLINE { RETURN[LOOPHOLE[Basics.DoubleShiftRight[LOOPHOLE[a], 1]]] };
END.