-
Notifications
You must be signed in to change notification settings - Fork 2
/
comfloat.f
executable file
·104 lines (103 loc) · 2.63 KB
/
comfloat.f
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
SUBROUTINE COMPAREFLOATINGNUMBERS(FIRSTVALUE,SECONDVALUE,
& STATUS)
*
* +---------------------------------------------------+
* | Copyright (c) FORMAT Int '03. All rights reserved |
* +---------------------------------------------------+
* | Subroutine : COMPAREFLOATINGNUMBERS |
* | Description: Compare for floating equality |
* | Revision : November 2003 |
* +---------------------------------------------------+
*
*------------------------
* Implicit definition *
*------------------------
*
IMPLICIT INTEGER (A-Z)
*
*------------------
* Indirect data *
*------------------
*
DOUBLE PRECISION FIRSTVALUE,SECONDVALUE
*
*---------------
* Local data *
*---------------
*
DOUBLE PRECISION DIFF,RATIO,ETOL
* DATA ETOL /0.000001D0/
DATA ETOL /0.0000000001D0/
*
*----------------------------------
* STATUS *
*----------------------------------
* *
* -1 = Firstvalue < Secondvalue *
* 0 = Firstvalue = Secondvalue *
* 1 = Firstvalue > Secondvalue *
*------------------------------------
*
*-----------------------------
* Test if values are equal *
*-----------------------------
*
IF(FIRSTVALUE.EQ.SECONDVALUE) THEN
STATUS=0
RETURN
END IF
*--------------------------------
* Test if first value is zero *
*--------------------------------
*
IF(FIRSTVALUE.EQ.0D0) THEN
IF(DABS(SECONDVALUE).LT.ETOL) THEN
STATUS=0
ELSE IF(SECONDVALUE.LT.0D0) THEN
STATUS=1
ELSE
STATUS=-1
END IF
RETURN
END IF
*
*---------------------------------
* Test if second value is zero *
*---------------------------------
*
IF(SECONDVALUE.EQ.0D0) THEN
IF(DABS(FIRSTVALUE).LT.ETOL) THEN
STATUS=0
ELSE IF(FIRSTVALUE.LT.0D0) THEN
STATUS=-1
ELSE
STATUS=1
END IF
RETURN
END IF
*
*---------------------------
* Perform magnitude test *
*---------------------------
*
DIFF=DABS(FIRSTVALUE-SECONDVALUE)
IF(DIFF.LE.DABS(FIRSTVALUE)) THEN
RATIO=DIFF/DABS(SECONDVALUE)
IF(RATIO.LT.ETOL) THEN
STATUS=0
RETURN
END IF
END IF
*
*---------------------------
* Magnitude test failure *
*---------------------------
*
IF(FIRSTVALUE.LT.SECONDVALUE) THEN
STATUS=-1
ELSE
STATUS=1
END IF
RETURN
*
END