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 !WARN: warning: NEAREST intrinsic folding overflow
10 real, parameter :: inf
= nearest(huge(1.), 1.)
11 !WARN: warning: NEAREST intrinsic folding: bad argument
12 logical, parameter :: test_5
= nearest(inf
, 1.) == inf
13 !WARN: warning: NEAREST intrinsic folding: bad argument
14 logical, parameter :: test_6
= nearest(-inf
, -1.) == -inf
15 logical, parameter :: test_7
= nearest(1.9999999, 1.) == 2.
16 logical, parameter :: test_8
= nearest(2., -1.) == 1.9999999
17 logical, parameter :: test_9
= nearest(1.9999999999999999999_10
, 1.) == 2._10
18 logical, parameter :: test_10
= nearest(-1., 1.) == -.99999994
19 logical, parameter :: test_11
= nearest(-1., -2.) == -1.0000001
20 real, parameter :: negZero
= sign(0., -1.)
21 logical, parameter :: test_12
= nearest(negZero
, 1.) == minSubnormal
22 logical, parameter :: test_13
= nearest(negZero
, -1.) == -minSubnormal
23 !WARN: warning: NEAREST: S argument is zero
24 logical, parameter :: test_14
= nearest(0., negZero
) == -minSubnormal
25 !WARN: warning: NEAREST: S argument is zero
26 logical, parameter :: test_15
= nearest(negZero
, 0.) == minSubnormal
30 use ieee_arithmetic
, only
: ieee_next_after
31 real, parameter :: minSubnormal
= 1.e
-45
32 logical, parameter :: test_0
= ieee_next_after(0., 0.) == 0.
33 logical, parameter :: test_1
= ieee_next_after(0., 1.) == minSubnormal
34 logical, parameter :: test_2
= ieee_next_after(minSubnormal
, -1.) == 0
35 logical, parameter :: test_3
= ieee_next_after(1., 2.) == 1.0000001
36 logical, parameter :: test_4
= ieee_next_after(1.0000001, -1.) == 1
37 !WARN: warning: division by zero
38 real, parameter :: inf
= 1. / 0.
39 logical, parameter :: test_5
= ieee_next_after(inf
, inf
) == inf
40 logical, parameter :: test_6
= ieee_next_after(inf
, -inf
) == inf
41 logical, parameter :: test_7
= ieee_next_after(-inf
, inf
) == -inf
42 logical, parameter :: test_8
= ieee_next_after(-inf
, -1.) == -inf
43 logical, parameter :: test_9
= ieee_next_after(1.9999999, 3.) == 2.
44 logical, parameter :: test_10
= ieee_next_after(2., 1.) == 1.9999999
45 logical, parameter :: test_11
= ieee_next_after(1.9999999999999999999_10
, 3.) == 2._10
46 logical, parameter :: test_12
= ieee_next_after(1., 1.) == 1.
47 !WARN: warning: invalid argument on division
48 real, parameter :: nan
= 0. / 0.
49 !WARN: warning: IEEE_NEXT_AFTER intrinsic folding: bad argument
50 real, parameter :: x13
= ieee_next_after(nan
, nan
)
51 logical, parameter :: test_13
= .not
. (x13
== x13
)
52 !WARN: warning: IEEE_NEXT_AFTER intrinsic folding: bad argument
53 real, parameter :: x14
= ieee_next_after(nan
, 0.)
54 logical, parameter :: test_14
= .not
. (x14
== x14
)
58 use ieee_arithmetic
, only
: ieee_next_up
, ieee_next_down
59 real(kind(0.d0
)), parameter :: minSubnormal
= 5.d
-324
60 logical, parameter :: test_1
= ieee_next_up(0.d0
) == minSubnormal
61 logical, parameter :: test_2
= ieee_next_down(0.d0
) == -minSubnormal
62 logical, parameter :: test_3
= ieee_next_up(1.d0
) == 1.0000000000000002d0
63 logical, parameter :: test_4
= ieee_next_down(1.0000000000000002d0) == 1.d0
64 !WARN: warning: division by zero
65 real(kind(0.d0
)), parameter :: inf
= 1.d0
/ 0.d0
66 !WARN: warning: IEEE_NEXT_UP intrinsic folding overflow
67 logical, parameter :: test_5
= ieee_next_up(huge(0.d0
)) == inf
68 !WARN: warning: IEEE_NEXT_DOWN intrinsic folding overflow
69 logical, parameter :: test_6
= ieee_next_down(-huge(0.d0
)) == -inf
70 !WARN: warning: IEEE_NEXT_UP intrinsic folding: bad argument
71 logical, parameter :: test_7
= ieee_next_up(inf
) == inf
72 !WARN: warning: IEEE_NEXT_DOWN intrinsic folding: bad argument
73 logical, parameter :: test_8
= ieee_next_down(inf
) == inf
74 !WARN: warning: IEEE_NEXT_UP intrinsic folding: bad argument
75 logical, parameter :: test_9
= ieee_next_up(-inf
) == -inf
76 !WARN: warning: IEEE_NEXT_DOWN intrinsic folding: bad argument
77 logical, parameter :: test_10
= ieee_next_down(-inf
) == -inf
78 logical, parameter :: test_11
= ieee_next_up(1.9999999999999997d0) == 2.d0
79 logical, parameter :: test_12
= ieee_next_down(2.d0
) == 1.9999999999999997d0
80 !WARN: warning: invalid argument on division
81 real(kind(0.d0
)), parameter :: nan
= 0.d0
/ 0.d0
82 !WARN: warning: IEEE_NEXT_UP intrinsic folding: bad argument
83 real(kind(0.d0
)), parameter :: x13
= ieee_next_up(nan
)
84 logical, parameter :: test_13
= .not
. (x13
== x13
)
85 !WARN: warning: IEEE_NEXT_DOWN intrinsic folding: bad argument
86 real(kind(0.d0
)), parameter :: x14
= ieee_next_down(nan
)
87 logical, parameter :: test_14
= .not
. (x14
== x14
)