-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathCHK_REAL.EXP
More file actions
executable file
·45 lines (36 loc) · 1.15 KB
/
Copy pathCHK_REAL.EXP
File metadata and controls
executable file
·45 lines (36 loc) · 1.15 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
(* @NESTEDCOMMENTS := 'Yes' *)
(* @PATH := '\/Logic\/gate logic' *)
(* @OBJECTFLAGS := '0, 8' *)
(* @SYMFILEFLAGS := '2048' *)
FUNCTION CHK_REAL : BYTE
VAR_INPUT
X : REAL;
END_VAR
VAR
pt : POINTER TO DWORD;
tmp : DWORD;
END_VAR
(*
version 1.0 20. jan. 2011
programmer hugo
tested by tobias
this function checks a floating point variable of type real (IEEE754-32Bits) for NAN and infinity
RETURN values: #0 = normal value, #20 = +infinity, #40 = -infinty, #80 = NAN
*)
(* @END_DECLARATION := '0' *)
pt := ADR(X); (* move real to dword, real_to_dword does not work becasze it treats dword as a number on many systems *)
tmp := ROL(pt^,1); (* rotate left foir easy checking, sign will be at lease significant digit *)
IF tmp < 16#FF000000 THEN
CHK_REAL := 16#00; (* normalized and denormalized numbers *)
ELSIF tmp = 16#FF000000 THEN
CHK_REAL := 16#20; (* X is +infinity see IEEE754 *)
ELSIF tmp = 16#FF000001 THEN
CHK_REAL := 16#40; (* X is -infinity see IEEE754 *)
ELSE
CHK_REAL := 16#80; (* X is NAN see IEEE754 *)
END_IF;
(* revision history
hm 20. jan. 2011 rev 1.0
original version
*)
END_FUNCTION