-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdmaceps.f90
30 lines (23 loc) · 864 Bytes
/
dmaceps.f90
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
SUBROUTINE dmaceps(mach_eps, i)
IMPLICIT NONE
REAL*8, INTENT(OUT) :: mach_eps
INTEGER, INTENT(OUT) :: i
REAL*8 :: one, approx
! Initialize variables. These are set an arbitrary number that we are
! going to use to determine the machine precision of the computer.
one = 1.0
mach_eps = 1.0
approx = one + mach_eps
! Do loop to calculate machine precision. Divides the arbitrary
! number chosen above by 2 at each iteration until the computer
! cannot tell the difference between `approx` and `one`.
DO i=1, 1000
mach_eps = mach_eps / 2.
approx = one + mach_eps
! If the computer cannot tell the difference between `approx`
! and `one`, the subroutine exits with `i` (the number of
! iterations), and `mach_eps` (machine precision).
IF(ABS(approx - one) == 0.0) RETURN
END DO
WRITE(*,*) "Loop limit exceeded."
END SUBROUTINE