DEFINITION MODULE TestReal; (* * $Id: TestReal.def,v 1.1 2015/09/13 20:48:41 mriedl Exp mriedl $ *) PROCEDURE Real4INF() : REAL; (*---------------------------------------------------------------*) (* Return INF for REAL*4 according to IEEE 754 *) (* *) (* mmmmmmmmmmmmmmmmmmmmmmmeeeeeeees *) (* 00000000000000000000000111111110 *) (* 01234567890123456789012345678901 *) (* 1 2 3 *) (* s = sign *) (* e = exponent (8 bits) *) (* m = mantissa (23 bits) *) (* *) (* All exponent bits set, all mantissa bits not set. To get *) (* -INF call x:=-Real4INF(); *) (*---------------------------------------------------------------*) PROCEDURE IsReal4INF(x : REAL) : BOOLEAN; (* x unendlich ? *) (*-----------------------------------------------------------*) (* Checks if x is +/- INF in IEEE 754 REAL*4 representation *) (* Sign of x is ignored, if sign is needed, compare x >= 0.0 *) (* or x < 0.0 outside of this procedure *) (*-----------------------------------------------------------*) PROCEDURE Real4NaNquite() : REAL; (*---------------------------------------------------------------*) (* Return a signaled or unsignaled NaN for REAL*4 according to *) (* IEEE 754 *) (* *) (* mmmmmmmmmmmmmmmmmmmmmma11111111s *) (* 01234567890123456789012345678901 *) (* 1 2 3 *) (* s = sign *) (* a = quite NAN (0) or signaling NAN (1) *) (* m = mantissa (including a) *) (* *) (* Please note that Real4NaN(quite|signaled) return one possible *) (* representation of a NaN for REAL*4 als all m-bits may or may *) (* not be set expect that at least one bit must be set to *) (* distiguish a signaled NaN from a INF as the sign bit is *) (* ignored. Call to Real4NaNsignaled can cause a runtime error *) (* if not trapped. *) (*---------------------------------------------------------------*) PROCEDURE Real4NaNsignaled() : REAL; (*---------------------------*) (* Details see Real4NaNquite *) (*---------------------------*) PROCEDURE IsReal4NaN(x : REAL) : BOOLEAN; (* x keine zul"assige Zahl ? *) (*----------------------------------------------------------*) (* Check if x is a REAL*4 NaN according to IEEE 754 *) (* Simple check is to test if x # x which is TRUE for *) (* a IEEE 754 NaN, this routine can be used if the compiler *) (* optimizes out that expression. *) (*----------------------------------------------------------*) PROCEDURE Real8INF() : LONGREAL; (*---------------------------------------------------------------*) (* Return a positive REAL*8 INF according to IEEE 754. *) (* Representation of most significant 4 byte word is *) (* *) (* mmmmmmmmmmmmmmmmmmmmeeeeeeeeeees *) (* 00000000000000000000111111111110 *) (* 01234567890123456789012345678901 *) (* 1 2 3 *) (* s = sign *) (* e = exponent (11 bits) *) (* m = mantissa (20 bits) *) (* *) (* and second 4 Byte Word completely for mantissa so that the *) (* mantissa is 32+(32-11-1) = 52 bits long *) (* *) (* So all exponent bits are set, all mantissa bits are not set. *) (* If -INF needed call x:=-Real8INF. *) (* *) (* Please note that Word 1 & 2 are swapped on big endian *) (* machines *) (*---------------------------------------------------------------*) PROCEDURE IsReal8INF(x : LONGREAL) : BOOLEAN; (* x unendlich ? *) (*-----------------------------------------------------------*) (* Checks if x is +/- INF in IEEE 754 REAL*8 representation *) (* Sign of x is ignored, if sign is needed, compare x >= 0.0 *) (* or x < 0.0 outside of this procedure *) (*-----------------------------------------------------------*) PROCEDURE Real8NaNquite() : LONGREAL; (*---------------------------------------------------------------*) (* Return a signaled or unsignaled NaN for REAL*4 according to *) (* IEEE 754. Representation of most significant 4 byte word is *) (* *) (* mmmmmmmmmmmmmmmmmmma11111111111s *) (* 01234567890123456789012345678901 *) (* 1 2 3 *) (* s = sign *) (* a = quite NAN (0) or signaling NAN (1) *) (* m = mantissa (including a) *) (* *) (* and second 4 Byte Word completely for mantissa so that the *) (* mantissa is 32+(32-11-1) = 52 bits long *) (* *) (* Please note that Real8NaN(quite|signaled) return one possible *) (* representation of a NaN for REAL*4 als all m-bits may or may *) (* not be set expect that at least one bit must be set to *) (* distiguish a signaled NaN from a INF as the sign bit is *) (* ignored. Call to Real8NaNsignaled can cause a runtime error *) (* if not trapped. *) (* *) (* Furthermore Word 1 & 2 are swapped on big endian machines *) (*---------------------------------------------------------------*) PROCEDURE Real8NaNsignaled() : LONGREAL; (*---------------------------*) (* Details see Real8NaNquite *) (*---------------------------*) PROCEDURE IsReal8NaN(x : LONGREAL) : BOOLEAN; (* x keine zul"assige Zahl ? *) (*----------------------------------------------------------*) (* Check if x is a REAL*8 NaN according to IEEE 754 *) (* Simple check is to test if x # x which is TRUE for *) (* a IEEE 754 NaN, this routine can be used if the compiler *) (* optimizes out that expression. *) (*----------------------------------------------------------*) END TestReal.