1 ! RUN: %python %S/test_folding.py %s %flang_fc1
2 ! Tests folding of NEAREST() and its relatives
4 real, parameter :: minSubnormal
= 1.e
-45
5 logical, parameter :: test_1
= nearest(0., 1.) == minSubnormal
6 logical, parameter :: test_2
= nearest(minSubnormal
, -1.) == 0
7 logical, parameter :: test_3
= nearest(1., 1.) == 1.0000001
8 logical, parameter :: test_4
= nearest(1.0000001, -1.) == 1
9 real, parameter :: inf
= nearest(huge(1.), 1.)
10 logical, parameter :: test_5
= nearest(inf
, 1.) == inf
11 logical, parameter :: test_6
= nearest(-inf
, -1.) == -inf
12 logical, parameter :: test_7
= nearest(1.9999999, 1.) == 2.
13 logical, parameter :: test_8
= nearest(2., -1.) == 1.9999999
15 logical, parameter :: test_9
= nearest(1.9999999999999999999_10
, 1.) == 2._10
17 logical, parameter :: test_10
= nearest(-1., 1.) == -.99999994
18 logical, parameter :: test_11
= nearest(-1., -2.) == -1.0000001
19 real, parameter :: negZero
= sign(0., -1.)
20 logical, parameter :: test_12
= nearest(negZero
, 1.) == minSubnormal
21 logical, parameter :: test_13
= nearest(negZero
, -1.) == -minSubnormal
22 !WARN: warning: NEAREST: S argument is zero
23 logical, parameter :: test_14
= nearest(0., negZero
) == -minSubnormal
24 !WARN: warning: NEAREST: S argument is zero
25 logical, parameter :: test_15
= nearest(negZero
, 0.) == minSubnormal
26 logical, parameter :: test_16
= nearest(tiny(1.),-1.) == 1.1754942E-38
27 logical, parameter :: test_17
= nearest(tiny(1.),1.) == 1.1754945E-38
31 !WARN: warning: NEAREST: S argument is zero
32 print *, nearest(a
, 0.)
37 use ieee_arithmetic
, only
: ieee_next_after
38 real, parameter :: minSubnormal
= 1.e
-45
39 real, parameter :: h
= huge(0.0)
40 logical, parameter :: test_0
= ieee_next_after(0., 0.) == 0.
41 logical, parameter :: test_1
= ieee_next_after(0., 1.) == minSubnormal
42 logical, parameter :: test_2
= ieee_next_after(minSubnormal
, -1.) == 0
43 logical, parameter :: test_3
= ieee_next_after(1., 2.) == 1.0000001
44 logical, parameter :: test_4
= ieee_next_after(1.0000001, -1.) == 1
45 !WARN: warning: division by zero
46 real, parameter :: inf
= 1. / 0.
47 logical, parameter :: test_5
= ieee_next_after(inf
, inf
) == inf
48 logical, parameter :: test_6
= ieee_next_after(inf
, -inf
) == h
49 logical, parameter :: test_7
= ieee_next_after(-inf
, inf
) == -h
50 logical, parameter :: test_8
= ieee_next_after(-inf
, -1.) == -h
51 logical, parameter :: test_9
= ieee_next_after(1.9999999, 3.) == 2.
52 logical, parameter :: test_10
= ieee_next_after(2., 1.) == 1.9999999
54 logical, parameter :: test_11
= ieee_next_after(1.9999999999999999999_10
, 3.) == 2._10
56 logical, parameter :: test_12
= ieee_next_after(1., 1.) == 1.
57 !WARN: warning: invalid argument on division
58 real, parameter :: nan
= 0. / 0.
59 !WARN: warning: IEEE_NEXT_AFTER intrinsic folding: arguments are unordered
60 real, parameter :: x13
= ieee_next_after(nan
, nan
)
61 logical, parameter :: test_13
= .not
. (x13
== x13
)
62 !WARN: warning: IEEE_NEXT_AFTER intrinsic folding: arguments are unordered
63 real, parameter :: x14
= ieee_next_after(nan
, 0.)
64 logical, parameter :: test_14
= .not
. (x14
== x14
)
68 use ieee_arithmetic
, only
: ieee_next_up
, ieee_next_down
69 real(kind(0.d0
)), parameter :: minSubnormal
= 5.d
-324
70 real(kind(0.d0
)), parameter :: h
= huge(0.d0
)
71 logical, parameter :: test_1
= ieee_next_up(0.d0
) == minSubnormal
72 logical, parameter :: test_2
= ieee_next_down(0.d0
) == -minSubnormal
73 logical, parameter :: test_3
= ieee_next_up(1.d0
) == 1.0000000000000002d0
74 logical, parameter :: test_4
= ieee_next_down(1.0000000000000002d0) == 1.d0
75 !WARN: warning: division by zero
76 real(kind(0.d0
)), parameter :: inf
= 1.d0
/ 0.d0
77 logical, parameter :: test_5
= ieee_next_up(huge(0.d0
)) == inf
78 logical, parameter :: test_6
= ieee_next_down(-huge(0.d0
)) == -inf
79 logical, parameter :: test_7
= ieee_next_up(inf
) == inf
80 logical, parameter :: test_8
= ieee_next_down(inf
) == h
81 logical, parameter :: test_9
= ieee_next_up(-inf
) == -h
82 logical, parameter :: test_10
= ieee_next_down(-inf
) == -inf
83 logical, parameter :: test_11
= ieee_next_up(1.9999999999999997d0) == 2.d0
84 logical, parameter :: test_12
= ieee_next_down(2.d0
) == 1.9999999999999997d0
85 !WARN: warning: invalid argument on division
86 real(kind(0.d0
)), parameter :: nan
= 0.d0
/ 0.d0
87 !WARN: warning: IEEE_NEXT_UP intrinsic folding: argument is NaN
88 real(kind(0.d0
)), parameter :: x13
= ieee_next_up(nan
)
89 logical, parameter :: test_13
= .not
. (x13
== x13
)
90 !WARN: warning: IEEE_NEXT_DOWN intrinsic folding: argument is NaN
91 real(kind(0.d0
)), parameter :: x14
= ieee_next_down(nan
)
92 logical, parameter :: test_14
= .not
. (x14
== x14
)
97 real(2), parameter :: neg_inf_2
= real(z
'fc00',2)
98 real(2), parameter :: neg_huge_2
= real(z
'fbff',2)
99 real(3), parameter :: neg_huge_3
= real(z
'ff7f',3)
100 logical, parameter :: test_1
= ieee_next_after(neg_inf_2
, neg_huge_3
) == neg_huge_2
106 real(8), parameter :: neg_inf_8
= real(z
'fff0000000000000',8)
107 real(8), parameter :: neg_huge_8
= real(z
'ffefffffffffffff',8)
108 real(10), parameter :: neg_one_10
= real(z
'bfff8000000000000000',10)
109 real(10), parameter :: neg_inf_10
= real(z
'ffff8000000000000000',10)
110 logical, parameter :: test_1
= ieee_next_after(neg_inf_8
, neg_one_10
) == neg_huge_8
111 logical, parameter :: test_2
= ieee_next_after(neg_one_10
, neg_inf_10
) == &
112 real(z
'bfff8000000000000001', 10)