c: Fix up pointer types to may_alias structures [PR114493]
[official-gcc.git] / gcc / testsuite / gfortran.dg / nearest_2.f90
blobe6c8f2290da98eacdf09f729014fec20bcd7d89e
1 ! { dg-do run }
2 ! { dg-options "-fno-range-check" }
3 ! { dg-add-options ieee }
5 ! PR fortran/34192
7 ! Test compile-time implementation of NEAREST
9 program test
10 implicit none
12 ! Single precision
14 ! 0+ > 0
15 if (nearest(0.0, 1.0) &
16 <= 0.0) &
17 STOP 1
18 ! 0++ > 0+
19 if (nearest(nearest(0.0, 1.0), 1.0) &
20 <= nearest(0.0, 1.0)) &
21 STOP 2
22 ! 0+++ > 0++
23 if (nearest(nearest(nearest(0.0, 1.0), 1.0), 1.0) &
24 <= nearest(nearest(0.0, 1.0), 1.0)) &
25 STOP 3
26 ! 0+- = 0
27 if (nearest(nearest(0.0, 1.0), -1.0) &
28 /= 0.0) &
29 STOP 4
30 ! 0++- = 0+
31 if (nearest(nearest(nearest(0.0, 1.0), 1.0), -1.0) &
32 /= nearest(0.0, 1.0)) &
33 STOP 5
34 ! 0++-- = 0
35 if (nearest(nearest(nearest(nearest(0.0, 1.0), 1.0), -1.0), -1.0) &
36 /= 0.0) &
37 STOP 6
39 ! 0- < 0
40 if (nearest(0.0, -1.0) &
41 >= 0.0) &
42 STOP 7
43 ! 0-- < 0+
44 if (nearest(nearest(0.0, -1.0), -1.0) &
45 >= nearest(0.0, -1.0)) &
46 STOP 8
47 ! 0--- < 0--
48 if (nearest(nearest(nearest(0.0, -1.0), -1.0), -1.0) &
49 >= nearest(nearest(0.0, -1.0), -1.0)) &
50 STOP 9
51 ! 0-+ = 0
52 if (nearest(nearest(0.0, -1.0), 1.0) &
53 /= 0.0) &
54 STOP 10
55 ! 0--+ = 0-
56 if (nearest(nearest(nearest(0.0, -1.0), -1.0), 1.0) &
57 /= nearest(0.0, -1.0)) &
58 STOP 11
59 ! 0--++ = 0
60 if (nearest(nearest(nearest(nearest(0.0, -1.0), -1.0), 1.0), 1.0) &
61 /= 0.0) &
62 STOP 12
64 ! 42++ > 42+
65 if (nearest(nearest(42.0, 1.0), 1.0) &
66 <= nearest(42.0, 1.0)) &
67 STOP 13
68 ! 42-- < 42-
69 if (nearest(nearest(42.0, -1.0), -1.0) &
70 >= nearest(42.0, -1.0)) &
71 STOP 14
72 ! 42-+ = 42
73 if (nearest(nearest(42.0, -1.0), 1.0) &
74 /= 42.0) &
75 STOP 15
76 ! 42+- = 42
77 if (nearest(nearest(42.0, 1.0), -1.0) &
78 /= 42.0) &
79 STOP 16
81 ! INF+ = INF
82 if (nearest(1.0/0.0, 1.0) /= 1.0/0.0) STOP 17
83 ! -INF- = -INF
84 if (nearest(-1.0/0.0, -1.0) /= -1.0/0.0) STOP 18
85 ! NAN- = NAN
86 if (.not.isnan(nearest(0.0d0/0.0, 1.0))) STOP 19
87 ! NAN+ = NAN
88 if (.not.isnan(nearest(0.0d0/0.0, -1.0))) STOP 20
90 ! Double precision
92 ! 0+ > 0
93 if (nearest(0.0d0, 1.0) &
94 <= 0.0d0) &
95 STOP 21
96 ! 0++ > 0+
97 if (nearest(nearest(0.0d0, 1.0), 1.0) &
98 <= nearest(0.0d0, 1.0)) &
99 STOP 22
100 ! 0+++ > 0++
101 if (nearest(nearest(nearest(0.0d0, 1.0), 1.0), 1.0) &
102 <= nearest(nearest(0.0d0, 1.0), 1.0)) &
103 STOP 23
104 ! 0+- = 0
105 if (nearest(nearest(0.0d0, 1.0), -1.0) &
106 /= 0.0d0) &
107 STOP 24
108 ! 0++- = 0+
109 if (nearest(nearest(nearest(0.0d0, 1.0), 1.0), -1.0) &
110 /= nearest(0.0d0, 1.0)) &
111 STOP 25
112 ! 0++-- = 0
113 if (nearest(nearest(nearest(nearest(0.0d0, 1.0), 1.0), -1.0), -1.0) &
114 /= 0.0d0) &
115 STOP 26
117 ! 0- < 0
118 if (nearest(0.0d0, -1.0) &
119 >= 0.0d0) &
120 STOP 27
121 ! 0-- < 0+
122 if (nearest(nearest(0.0d0, -1.0), -1.0) &
123 >= nearest(0.0d0, -1.0)) &
124 STOP 28
125 ! 0--- < 0--
126 if (nearest(nearest(nearest(0.0d0, -1.0), -1.0), -1.0) &
127 >= nearest(nearest(0.0d0, -1.0), -1.0)) &
128 STOP 29
129 ! 0-+ = 0
130 if (nearest(nearest(0.0d0, -1.0), 1.0) &
131 /= 0.0d0) &
132 STOP 30
133 ! 0--+ = 0-
134 if (nearest(nearest(nearest(0.0d0, -1.0), -1.0), 1.0) &
135 /= nearest(0.0d0, -1.0)) &
136 STOP 31
137 ! 0--++ = 0
138 if (nearest(nearest(nearest(nearest(0.0d0, -1.0), -1.0), 1.0), 1.0) &
139 /= 0.0d0) &
140 STOP 32
142 ! 42++ > 42+
143 if (nearest(nearest(42.0d0, 1.0), 1.0) &
144 <= nearest(42.0d0, 1.0)) &
145 STOP 33
146 ! 42-- < 42-
147 if (nearest(nearest(42.0d0, -1.0), -1.0) &
148 >= nearest(42.0d0, -1.0)) &
149 STOP 34
150 ! 42-+ = 42
151 if (nearest(nearest(42.0d0, -1.0), 1.0) &
152 /= 42.0d0) &
153 STOP 35
154 ! 42+- = 42
155 if (nearest(nearest(42.0d0, 1.0), -1.0) &
156 /= 42.0d0) &
157 STOP 36
159 ! INF+ = INF
160 if (nearest(1.0d0/0.0d0, 1.0) /= 1.0d0/0.0d0) STOP 37
161 ! -INF- = -INF
162 if (nearest(-1.0d0/0.0d0, -1.0) /= -1.0d0/0.0d0) STOP 38
163 ! NAN- = NAN
164 if (.not.isnan(nearest(0.0d0/0.0, 1.0))) STOP 39
165 ! NAN+ = NAN
166 if (.not.isnan(nearest(0.0d0/0.0, -1.0))) STOP 40
167 end program test