Scaled:
CEDAR DEFINITIONS IMPORTS Real =
BEGIN
Value: TYPE = MACHINE DEPENDENT RECORD [fraction: CARDINAL ← 0, integerPart: INTEGER];
zero: Value = [0, 0];
one, unit: Value = [integerPart: 1];
epsilon: Value = [integerPart: 0, fraction: 1];
oneMinusEpsilon: Value = [integerPart: 0, fraction: LAST[CARDINAL]];
half: Value = [fraction: LAST[NAT]+1, integerPart: 0];
infinity: Value = LOOPHOLE[LAST[INT]];
negInfinity: Value = LOOPHOLE[FIRST[INT]];
FromInt: PROC [int: INT] RETURNS [Value] = INLINE {RETURN[[integerPart: int, fraction: 0]]};
FromReal: PROC [real: REAL] RETURNS [Value];
PLUS:
PROC [a, b: Value]
RETURNS [Value] =
TRUSTED INLINE
{RETURN[LOOPHOLE[LOOPHOLE[a, INT] + LOOPHOLE[b, INT]]]};
MINUS:
PROC [a, b: Value]
RETURNS [Value] =
TRUSTED INLINE
{RETURN[LOOPHOLE[LOOPHOLE[a, INT] - LOOPHOLE[b, INT]]]};
UMINUS:
PROC [a: Value]
RETURNS [Value] =
TRUSTED INLINE
{RETURN[LOOPHOLE[-LOOPHOLE[a, INT]]]};
TIMES: PROC [a, b: Value] RETURNS [Value];
DIVIDE: PROC [a, b: Value] RETURNS [Value];
GREATER:
PROC [a, b: Value]
RETURNS [
BOOLEAN] =
TRUSTED INLINE
{RETURN[LOOPHOLE[a, INT] > LOOPHOLE[b, INT]]};
LESS:
PROC [a, b: Value]
RETURNS [
BOOLEAN] =
TRUSTED INLINE
{RETURN[LOOPHOLE[a, INT] < LOOPHOLE[b, INT]]};
Floor: PROC [a: Value] RETURNS [INT] = INLINE {RETURN[a.integerPart]};
Ceiling: PROC [a: Value] RETURNS [INT] = INLINE {RETURN[Floor[a.PLUS[oneMinusEpsilon]]]};
Round: PROC [a: Value] RETURNS [INT] = INLINE {RETURN[Floor[a.PLUS[half]]]};
Float: PROC [a: Value] RETURNS [REAL] = INLINE {RETURN[Real.FScale[LOOPHOLE[a, INT], -Environment.bitsPerWord]]};
Scale: PROC [a: Value, scale: INTEGER] RETURNS [Value];
END.