IPRealImpl.mesa
Last edited by:
Doug Wyatt, February 11, 1984 4:26:39 pm PST
DIRECTORY
IPReal USING [],
Real USING [Fix, RealException];
IPRealImpl: CEDAR PROGRAM
IMPORTS Real
EXPORTS IPReal
= BEGIN
Fix: PRIVATE PROC[r: REAL] RETURNS[INT] = { RETURN[Real.Fix[r]] };
This procedure copes with a "feature" of Mesa's signal handling. Because Real.Fix actually compiles into machine code, any signal it raises cannot be caught in the statement that invokes it; the catch phrase must be at least one procedure call away. To fix a real number and catch any exception, say Fix[r ! Real.RealException => GOTO Fail];
Floor: PUBLIC PROC[a: REAL] RETURNS[c: REAL] = {
c ← Fix[a ! Real.RealException => { c ← a; CONTINUE }];
IF c>a THEN RETURN[c-1] ELSE RETURN[c]
};
Ceiling: PUBLIC PROC[a: REAL] RETURNS[c: REAL] = {
c ← Fix[a ! Real.RealException => { c ← a; CONTINUE }];
IF c<a THEN RETURN[c+1] ELSE RETURN[c]
};
Trunc: PUBLIC PROC[a: REAL] RETURNS[c: REAL] = {
c ← Fix[a ! Real.RealException => { c ← a; CONTINUE }];
RETURN[c]
};
Round: PUBLIC PROC[a: REAL] RETURNS[c: REAL] = {
RETURN[Floor[a + 0.5]]
};
Mod: PUBLIC PROC[a, b: REAL] RETURNS[REAL] = {
RETURN[a - b*Floor[a/b]]
};
Rem: PUBLIC PROC[a, b: REAL] RETURNS[REAL] = {
RETURN[a - b*Trunc[a/b]]
};
END.