2 ! { dg-add-options ieee }
3 ! { dg-skip-if "NaN not supported" { spu-*-* } }
7 ! Test run-time implementation of NEAREST
11 real(4), volatile :: r4
12 real(8), volatile :: r8
14 ! Single precision with single-precision sign
18 if (nearest(r4
, 1.0) &
22 if (nearest(nearest(r4
, 1.0), 1.0) &
23 <= nearest(r4
, 1.0)) &
26 if (nearest(nearest(nearest(r4
, 1.0), 1.0), 1.0) &
27 <= nearest(nearest(r4
, 1.0), 1.0)) &
30 if (nearest(nearest(r4
, 1.0), -1.0) &
34 if (nearest(nearest(nearest(r4
, 1.0), 1.0), -1.0) &
35 /= nearest(r4
, 1.0)) &
38 if (nearest(nearest(nearest(nearest(r4
, 1.0), 1.0), -1.0), -1.0) &
43 if (nearest(r4
, -1.0) &
47 if (nearest(nearest(r4
, -1.0), -1.0) &
48 >= nearest(r4
, -1.0)) &
51 if (nearest(nearest(nearest(r4
, -1.0), -1.0), -1.0) &
52 >= nearest(nearest(r4
, -1.0), -1.0)) &
55 if (nearest(nearest(r4
, -1.0), 1.0) &
59 if (nearest(nearest(nearest(r4
, -1.0), -1.0), 1.0) &
60 /= nearest(r4
, -1.0)) &
63 if (nearest(nearest(nearest(nearest(r4
, -1.0), -1.0), 1.0), 1.0) &
69 if (nearest(nearest(r4
, 1.0), 1.0) &
70 <= nearest(r4
, 1.0)) &
73 if (nearest(nearest(r4
, -1.0), -1.0) &
74 >= nearest(r4
, -1.0)) &
77 if (nearest(nearest(r4
, -1.0), 1.0) &
81 if (nearest(nearest(r4
, 1.0), -1.0) &
87 if (nearest(1.0/r4
, 1.0) /= 1.0/r4
) call abort()
89 if (nearest(-1.0/r4
, -1.0) /= -1.0/r4
) call abort()
91 if (.not
.isnan(nearest(0.0/r4
, 1.0))) call abort()
93 if (.not
.isnan(nearest(0.0/r4
, -1.0))) call abort()
95 ! Double precision with single-precision sign
99 if (nearest(r8
, 1.0) &
103 if (nearest(nearest(r8
, 1.0), 1.0) &
104 <= nearest(r8
, 1.0)) &
107 if (nearest(nearest(nearest(r8
, 1.0), 1.0), 1.0) &
108 <= nearest(nearest(r8
, 1.0), 1.0)) &
111 if (nearest(nearest(r8
, 1.0), -1.0) &
115 if (nearest(nearest(nearest(r8
, 1.0), 1.0), -1.0) &
116 /= nearest(r8
, 1.0)) &
119 if (nearest(nearest(nearest(nearest(r8
, 1.0), 1.0), -1.0), -1.0) &
124 if (nearest(r8
, -1.0) &
128 if (nearest(nearest(r8
, -1.0), -1.0) &
129 >= nearest(r8
, -1.0)) &
132 if (nearest(nearest(nearest(r8
, -1.0), -1.0), -1.0) &
133 >= nearest(nearest(r8
, -1.0), -1.0)) &
136 if (nearest(nearest(r8
, -1.0), 1.0) &
140 if (nearest(nearest(nearest(r8
, -1.0), -1.0), 1.0) &
141 /= nearest(r8
, -1.0)) &
144 if (nearest(nearest(nearest(nearest(r8
, -1.0), -1.0), 1.0), 1.0) &
150 if (nearest(nearest(r8
, 1.0), 1.0) &
151 <= nearest(r8
, 1.0)) &
154 if (nearest(nearest(r8
, -1.0), -1.0) &
155 >= nearest(r8
, -1.0)) &
158 if (nearest(nearest(r8
, -1.0), 1.0) &
162 if (nearest(nearest(r8
, 1.0), -1.0) &
168 if (nearest(1.0/r4
, 1.0) /= 1.0/r4
) call abort()
170 if (nearest(-1.0/r4
, -1.0) /= -1.0/r4
) call abort()
172 if (.not
.isnan(nearest(0.0/r4
, 1.0))) call abort()
174 if (.not
.isnan(nearest(0.0/r4
, -1.0))) call abort()
177 ! Single precision with double-precision sign
181 if (nearest(r4
, 1.0d0) &
185 if (nearest(nearest(r4
, 1.0d0), 1.0d0) &
186 <= nearest(r4
, 1.0d0)) &
189 if (nearest(nearest(nearest(r4
, 1.0d0), 1.0d0), 1.0d0) &
190 <= nearest(nearest(r4
, 1.0d0), 1.0d0)) &
193 if (nearest(nearest(r4
, 1.0d0), -1.0d0) &
197 if (nearest(nearest(nearest(r4
, 1.0d0), 1.0d0), -1.0d0) &
198 /= nearest(r4
, 1.0d0)) &
201 if (nearest(nearest(nearest(nearest(r4
, 1.0d0), 1.0d0), -1.0d0), -1.0d0) &
206 if (nearest(r4
, -1.0d0) &
210 if (nearest(nearest(r4
, -1.0d0), -1.0d0) &
211 >= nearest(r4
, -1.0d0)) &
214 if (nearest(nearest(nearest(r4
, -1.0d0), -1.0d0), -1.0d0) &
215 >= nearest(nearest(r4
, -1.0d0), -1.0d0)) &
218 if (nearest(nearest(r4
, -1.0d0), 1.0d0) &
222 if (nearest(nearest(nearest(r4
, -1.0d0), -1.0d0), 1.0d0) &
223 /= nearest(r4
, -1.0d0)) &
226 if (nearest(nearest(nearest(nearest(r4
, -1.0d0), -1.0d0), 1.0d0), 1.0d0) &
232 if (nearest(nearest(r4
, 1.0d0), 1.0d0) &
233 <= nearest(r4
, 1.0d0)) &
236 if (nearest(nearest(r4
, -1.0d0), -1.0d0) &
237 >= nearest(r4
, -1.0d0)) &
240 if (nearest(nearest(r4
, -1.0d0), 1.0d0) &
244 if (nearest(nearest(r4
, 1.0d0), -1.0d0) &
250 if (nearest(1.0d0/r4
, 1.0d0) /= 1.0d0/r4
) call abort()
252 if (nearest(-1.0d0/r4
, -1.0d0) /= -1.0d0/r4
) call abort()
254 if (.not
.isnan(nearest(0.0/r4
, 1.0d0))) call abort()
256 if (.not
.isnan(nearest(0.0/r4
, -1.0d0))) call abort()
258 ! Double precision with double-precision sign
262 if (nearest(r8
, 1.0d0) &
266 if (nearest(nearest(r8
, 1.0d0), 1.0d0) &
267 <= nearest(r8
, 1.0d0)) &
270 if (nearest(nearest(nearest(r8
, 1.0d0), 1.0d0), 1.0d0) &
271 <= nearest(nearest(r8
, 1.0d0), 1.0d0)) &
274 if (nearest(nearest(r8
, 1.0d0), -1.0d0) &
278 if (nearest(nearest(nearest(r8
, 1.0d0), 1.0d0), -1.0d0) &
279 /= nearest(r8
, 1.0d0)) &
282 if (nearest(nearest(nearest(nearest(r8
, 1.0d0), 1.0d0), -1.0d0), -1.0d0) &
287 if (nearest(r8
, -1.0d0) &
291 if (nearest(nearest(r8
, -1.0d0), -1.0d0) &
292 >= nearest(r8
, -1.0d0)) &
295 if (nearest(nearest(nearest(r8
, -1.0d0), -1.0d0), -1.0d0) &
296 >= nearest(nearest(r8
, -1.0d0), -1.0d0)) &
299 if (nearest(nearest(r8
, -1.0d0), 1.0d0) &
303 if (nearest(nearest(nearest(r8
, -1.0d0), -1.0d0), 1.0d0) &
304 /= nearest(r8
, -1.0d0)) &
307 if (nearest(nearest(nearest(nearest(r8
, -1.0d0), -1.0d0), 1.0d0), 1.0d0) &
313 if (nearest(nearest(r8
, 1.0d0), 1.0d0) &
314 <= nearest(r8
, 1.0d0)) &
317 if (nearest(nearest(r8
, -1.0d0), -1.0d0) &
318 >= nearest(r8
, -1.0d0)) &
321 if (nearest(nearest(r8
, -1.0d0), 1.0d0) &
325 if (nearest(nearest(r8
, 1.0d0), -1.0d0) &
331 if (nearest(1.0d0/r4
, 1.0d0) /= 1.0d0/r4
) call abort()
333 if (nearest(-1.0d0/r4
, -1.0d0) /= -1.0d0/r4
) call abort()
335 if (.not
.isnan(nearest(0.0/r4
, 1.0d0))) call abort()
337 if (.not
.isnan(nearest(0.0/r4
, -1.0d0))) call abort()