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
|
c-------------------------------------------------------------------------
c ZZEPS2.F -- Alternate version of ZZEPS. This version may avoid problems
c seen on some systems of excess precision causing an artificially large
c value of the single precision epsilon to be computed, due to the epsilon
c value being computed in registers. Use whichever version produces the
c smaller epsilon.
c
c Compute machine epsilon, i.e, the smallest real or double precision
c number EPS such that (1.0 + EPS > 1.0). This calculation is tricky
c because of the optimizations performed by some compilers, and because
c a comparison performed in registers may be done to a higher precision
c than one involving variables. This program contains some minor
c violations of the F78 standard.
c-------------------------------------------------------------------------
program epsilo
real seps
double precision deps
write (*,*) 'Calculate Machine Epsilon ------'
call cseps (seps)
call cdeps (deps)
write (*,*) ' single precision epsilon: ', seps
write (*,*) ' double precision epsilon: ', deps
write (*,*) ' '
write (*,*) 'Verify Values -----'
write (*, '('' enter s.p. epsilon: '',$)')
read (*,*) seps
if (1.0 + seps .gt. 1.0) then
write (*,*) ' ok'
else
write (*,*) ' not ok'
endif
write (*, '('' enter d.p. epsilon: '',$)')
read (*,*) deps
if (1.0 + deps .gt. 1.0) then
write (*,*) ' ok'
else
write (*,*) ' not ok'
endif
stop
end
c -- Compute the single precision epsilon.
subroutine cseps (seps)
real seps
real sval
double precision dval
logical sgt
common /eps/ sval, dval
save /eps/
sval = 1.0
10 seps = sval
sval = sval / 2.0
if (sgt (sval + 1.0, 1.0)) then
goto 10
endif
end
c -- Is SVAL + 1.0 greater than 1.0?
logical function sgt (value, ref)
real value, ref
sgt = (value .gt. ref)
end
c -- Compute the double precision epsilon.
subroutine cdeps (deps)
double precision deps
double precision dval
real sval
logical dgt
common /eps/ sval, dval
save /eps/
dval = 1.0d0
10 deps = dval
dval = dval / 2.0d0
if (dgt (dval + 1.0d0, 1.0d0)) then
goto 10
endif
end
c -- Is DVAL + 1.0 greater than 1.0?
logical function dgt (value, ref)
double precision value, ref
dgt = (value .gt. ref)
end
|