-
Notifications
You must be signed in to change notification settings - Fork 1
/
inf.f90
107 lines (86 loc) · 2.57 KB
/
inf.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
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
module inf_mod
! infnan_mod together with inf_mod provides functions for checking Inf/NaN. They aim to work even when
! compilers are invoked with aggressive optimization flags, e.g., `gfortran -Ofast`.
! See infnan.f90 for more comments.
use, non_intrinsic :: huge_mod, only : huge_value
implicit none
private
public :: is_finite, is_inf, is_posinf, is_neginf
interface is_finite
module procedure is_finite_sp, is_finite_dp
end interface is_finite
interface is_posinf
module procedure is_posinf_sp, is_posinf_dp
end interface is_posinf
interface is_neginf
module procedure is_neginf_sp, is_neginf_dp
end interface is_neginf
interface is_inf
module procedure is_inf_sp, is_inf_dp
end interface is_inf
contains
elemental pure function is_finite_sp(x) result(y)
use consts_mod, only : SP
implicit none
real(SP), intent(in) :: x
logical :: y
y = (x <= huge_value(x) .and. x >= -huge_value(x))
!y = (x < posinf(x) .and. x > neginf(x))
end function is_finite_sp
elemental pure function is_finite_dp(x) result(y)
use consts_mod, only : DP
implicit none
real(DP), intent(in) :: x
logical :: y
y = (x <= huge_value(x) .and. x >= -huge_value(x))
!y = (x < posinf(x) .and. x > neginf(x))
end function is_finite_dp
elemental pure function is_inf_sp(x) result(y)
use consts_mod, only : SP
implicit none
real(SP), intent(in) :: x
logical :: y
y = (abs(x) > huge_value(x))
!y = (abs(x) >= posinf(x))
end function is_inf_sp
elemental pure function is_inf_dp(x) result(y)
use consts_mod, only : DP
implicit none
real(DP), intent(in) :: x
logical :: y
y = (abs(x) > huge_value(x))
!y = (abs(x) >= posinf(x))
end function is_inf_dp
elemental pure function is_posinf_sp(x) result(y)
use consts_mod, only : SP
implicit none
real(SP), intent(in) :: x
logical :: y
y = (abs(x) > huge_value(x)) .and. (x > 0)
!y = ((abs(x) >= posinf(x)) .and. (x > 0))
end function is_posinf_sp
elemental pure function is_posinf_dp(x) result(y)
use consts_mod, only : DP
implicit none
real(DP), intent(in) :: x
logical :: y
y = (abs(x) > huge_value(x)) .and. (x > 0)
!y = ((abs(x) >= posinf(x)) .and. (x > 0))
end function is_posinf_dp
elemental pure function is_neginf_sp(x) result(y)
use consts_mod, only : SP
implicit none
real(SP), intent(in) :: x
logical :: y
y = (abs(x) > huge_value(x)) .and. (x < 0)
!y = ((abs(x) >= posinf(x)) .and. (x < 0))
end function is_neginf_sp
elemental pure function is_neginf_dp(x) result(y)
use consts_mod, only : DP
implicit none
real(DP), intent(in) :: x
logical :: y
y = (abs(x) > huge_value(x)) .and. (x < 0)
!y = ((abs(x) >= posinf(x)) .and. (x < 0))
end function is_neginf_dp
end module inf_mod