FloatingPointCommon.mesa
Copyright Ó 1989, 1991 by Xerox Corporation. All rights reserved.
Russ Atkinson (RRA) June 22, 1989 1:23:55 pm PDT
This interface describes the common flags and exceptions shared by REAL and DREAL support. Exceptions do not distinguish between REAL and DREAL operations.
FloatingPointCommon: CEDAR DEFINITIONS = BEGIN
Flag: TYPE = BOOL ¬ FALSE;
Exception: TYPE = MACHINE DEPENDENT {
invalidOperation, -- bad argument, bad operation, other fatal error
overflow,  -- floating point overflow (result would be out of range)
divisionByZero, -- division by zero
underflow,  -- floating point underflow
inexactResult, -- result would be inexact
other  -- any other reason
};
Although these exceptions are based on the IEEE standard, it is permitted to not support all of them.
ExceptionFlags: TYPE = PACKED ARRAY Exception OF Flag;
NoExceptions: ExceptionFlags = ALL[FALSE];
AllExceptions: ExceptionFlags = ALL[TRUE];
NumberType: TYPE = MACHINE DEPENDENT {
zero, -- +0.0 or -0.0
subnormal, -- denormalized numbers
normal, -- normalized numbers
infinity, -- +infinity or -infinity
quiet, -- a quiet (non-signaling) NaN (Not a Number)
signaling, -- a signaling NaN (Not a Number)
other}; -- any other pattern that is NaN
Although these number types are based on the IEEE standard, floating point support is allowed that fits in as a subset of the IEEE standard. For example, floating point support that does not include denormalized numbers (subnormal) is explicitly allowed.
ValidNumberType: TYPE = NumberType[zero..normal];
A REAL or DREAL number with this classification corresponds to an actual point on the real number line.
Error: ERROR [code: Exception];
Error is raised if any supported exceptions occurs. The code argument reports the kind of exception. No resumption is possible.
SupportedExceptionErrors: PROC RETURNS [ExceptionFlags];
This operation indicates which exception flags are supported by Error. It is permitted for none of the flags to be supported by the primitive operations.
SupportedStickyFlags: PROC RETURNS [ExceptionFlags];
This operation indicates which exception flags are supported by GetStickyFlags and SetStickyFlags. It is permitted for none of the flags to be supported.
GetStickyFlags: PROC RETURNS [ExceptionFlags];
SetStickyFlags: PROC [new: ExceptionFlags ¬ NoExceptions] RETURNS [old: ExceptionFlags];
The various exceptions may have independent "sticky" flags that remember if the exception has occurred since the last call to SetStickyFlags. SetStickyFlags is provided so that procedures may save and restore the state for others.
END.