RealExtrasImpl.mesa
Copyright © 1984 Xerox Corporation. All rights reserved.
Doug Wyatt, August 13, 1984 4:20:07 pm PDT
DIRECTORY
RealExtras USING [],
Real USING [Fix, RealException];
RealExtrasImpl: CEDAR PROGRAM
IMPORTS Real
EXPORTS RealExtras
= 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.