Parent: [c017f0] (diff)

Download this file

TestReal.def    160 lines (132 with data), 9.5 kB

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
DEFINITION MODULE TestReal;
(*------------------------------------------------------------------------*)
(* Testen von REAL-Variablen auf NAN & INF. *)
(* Check REAL values for beeing NAN or INF. *)
(*------------------------------------------------------------------------*)
(* Implementation : Michael Riedl *)
(* Licence : GNU Lesser General Public License (LGPL) *)
(*------------------------------------------------------------------------*)
(* $Id: TestReal.def,v 1.2 2018/06/08 21:38:43 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. *)
(*----------------------------------------------------------*)
PROCEDURE IsValidReal8(x : LONGREAL) : BOOLEAN;
(*---------------------------------------------------------------*)
(* Check if x is neither NAN nor INF *)
(*---------------------------------------------------------------*)
PROCEDURE IsNearInteger(x : LONGREAL) : BOOLEAN;
(*---------------------------------------------------------------*)
(* Check if x is (near) to an integer value *)
(*---------------------------------------------------------------*)
END TestReal.