1 ! Test if MIN and MAX intrinsics behave correctly when passed NaNs
5 ! { dg-add-options ieee }
6 ! { dg-skip-if "NaN not supported" { spu-*-* } }
10 module procedure isnan_r
11 module procedure isnan_d
15 module procedure isinf_r
16 module procedure isinf_d
20 pure
function isnan_r(x
) result (isnan
)
24 isnan
= (.not
.(x
== x
))
27 pure
function isnan_d(x
) result (isnan
)
29 double precision, intent(in
) :: x
31 isnan
= (.not
.(x
== x
))
34 pure
function isinf_r(x
) result (isinf
)
38 isinf
= (x
> huge(x
)) .or
. (x
< -huge(x
))
41 pure
function isinf_d(x
) result (isinf
)
43 double precision, intent(in
) :: x
45 isinf
= (x
> huge(x
)) .or
. (x
< -huge(x
))
52 real :: nan
, large
, inf
54 ! Create a NaN and check it
57 if (nan
== nan
.or
. nan
> nan
.or
. nan
< nan
.or
. nan
>= nan
&
58 .or
. nan
<= nan
) STOP 1
59 if (isnan (2.d0
) .or
. (.not
. isnan(nan
)) .or
. &
60 (.not
. isnan(real(nan
,kind
=kind(2.d0
))))) STOP 2
62 ! Create an INF and check it
65 if (isinf(nan
) .or
. isinf(large
) .or
. .not
. isinf(inf
)) STOP 3
66 if (isinf(-nan
) .or
. isinf(-large
) .or
. .not
. isinf(-inf
)) STOP 4
68 ! Check that MIN and MAX behave correctly
70 if (.not
. isnan(min(nan
,nan
))) STOP 13
71 if (.not
. isnan(max(nan
,nan
))) STOP 14
73 ! Same thing, with more arguments
75 if (.not
. isnan(min(nan
,nan
,nan
))) STOP 27
76 if (.not
. isnan(max(nan
,nan
,nan
))) STOP 28
77 if (.not
. isnan(min(nan
,nan
,nan
,nan
))) STOP 29
78 if (.not
. isnan(max(nan
,nan
,nan
,nan
))) STOP 30
79 if (.not
. isnan(min(nan
,nan
,nan
,nan
,nan
))) STOP 31
80 if (.not
. isnan(max(nan
,nan
,nan
,nan
,nan
))) STOP 32
82 ! Large values, INF and NaNs
83 if (.not
. isinf(max(large
, inf
))) STOP 33
84 if (isinf(min(large
, inf
))) STOP 34
86 if (.not
. isinf(min(-large
, -inf
))) STOP 41
87 if (isinf(max(-large
, -inf
))) STOP 42