1//===-- Utility class to test different flavors of fromfpx ------*- C++ -*-===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9#ifndef LIBC_TEST_SRC_MATH_SMOKE_FROMFPXTEST_H
10#define LIBC_TEST_SRC_MATH_SMOKE_FROMFPXTEST_H
11
12#include "test/UnitTest/FEnvSafeTest.h"
13#include "test/UnitTest/FPMatcher.h"
14#include "test/UnitTest/Test.h"
15
16template <typename T>
17class FromfpxTestTemplate : public LIBC_NAMESPACE::testing::FEnvSafeTest {
18
19 DECLARE_SPECIAL_CONSTANTS(T)
20
21public:
22 typedef T (*FromfpxFunc)(T, int, unsigned int);
23
24 void testSpecialNumbersNonzeroWidth(FromfpxFunc func) {
25 for (int rnd : MATH_ROUNDING_DIRECTIONS_INCLUDING_UNKNOWN) {
26 EXPECT_FP_EQ(zero, func(zero, rnd, 32U));
27 EXPECT_FP_EQ(neg_zero, func(neg_zero, rnd, 32U));
28
29 EXPECT_FP_EQ_WITH_EXCEPTION(aNaN, func(inf, rnd, 32U), FE_INVALID);
30 EXPECT_FP_EQ_WITH_EXCEPTION(aNaN, func(neg_inf, rnd, 32U), FE_INVALID);
31
32 EXPECT_FP_EQ_WITH_EXCEPTION(aNaN, func(aNaN, rnd, 32U), FE_INVALID);
33 }
34 }
35
36 void testSpecialNumbersZeroWidth(FromfpxFunc func) {
37 for (int rnd : MATH_ROUNDING_DIRECTIONS_INCLUDING_UNKNOWN) {
38 EXPECT_FP_EQ_WITH_EXCEPTION(aNaN, func(zero, rnd, 0U), FE_INVALID);
39 EXPECT_FP_EQ_WITH_EXCEPTION(aNaN, func(neg_zero, rnd, 0U), FE_INVALID);
40
41 EXPECT_FP_EQ_WITH_EXCEPTION(aNaN, func(inf, rnd, 0U), FE_INVALID);
42 EXPECT_FP_EQ_WITH_EXCEPTION(aNaN, func(neg_inf, rnd, 0U), FE_INVALID);
43
44 EXPECT_FP_EQ_WITH_EXCEPTION(aNaN, func(aNaN, rnd, 0U), FE_INVALID);
45 }
46 }
47
48 void testRoundedNumbersWithinRange(FromfpxFunc func) {
49 for (int rnd : MATH_ROUNDING_DIRECTIONS_INCLUDING_UNKNOWN) {
50 EXPECT_FP_EQ(T(1.0), func(T(1.0), rnd, 2U));
51 EXPECT_FP_EQ(T(-1.0), func(T(-1.0), rnd, 1U));
52 EXPECT_FP_EQ(T(10.0), func(T(10.0), rnd, 5U));
53 EXPECT_FP_EQ(T(-10.0), func(T(-10.0), rnd, 5U));
54 EXPECT_FP_EQ(T(1234.0), func(T(1234.0), rnd, 12U));
55 EXPECT_FP_EQ(T(-1234.0), func(T(-1234.0), rnd, 12U));
56 EXPECT_FP_EQ(T(1234.0), func(T(1234.0), rnd, 65U));
57 EXPECT_FP_EQ(T(-1234.0), func(T(-1234.0), rnd, 65U));
58 }
59 }
60
61 void testRoundedNumbersOutsideRange(FromfpxFunc func) {
62 for (int rnd : MATH_ROUNDING_DIRECTIONS_INCLUDING_UNKNOWN) {
63 EXPECT_FP_EQ_WITH_EXCEPTION(aNaN, func(T(1.0), rnd, 1U), FE_INVALID);
64 EXPECT_FP_EQ_WITH_EXCEPTION(aNaN, func(T(10.0), rnd, 4U), FE_INVALID);
65 EXPECT_FP_EQ_WITH_EXCEPTION(aNaN, func(T(-10.0), rnd, 4U), FE_INVALID);
66 EXPECT_FP_EQ_WITH_EXCEPTION(aNaN, func(T(1234.0), rnd, 11U), FE_INVALID);
67 EXPECT_FP_EQ_WITH_EXCEPTION(aNaN, func(T(-1234.0), rnd, 11U), FE_INVALID);
68 }
69 }
70
71 void testFractionsUpwardWithinRange(FromfpxFunc func) {
72 EXPECT_FP_EQ_WITH_EXCEPTION(T(1.0), func(T(0.5), FP_INT_UPWARD, 2U),
73 FE_INEXACT);
74 EXPECT_FP_EQ_WITH_EXCEPTION(T(-0.0), func(T(-0.5), FP_INT_UPWARD, 1U),
75 FE_INEXACT);
76 EXPECT_FP_EQ_WITH_EXCEPTION(T(1.0), func(T(0.115), FP_INT_UPWARD, 2U),
77 FE_INEXACT);
78 EXPECT_FP_EQ_WITH_EXCEPTION(T(-0.0), func(T(-0.115), FP_INT_UPWARD, 1U),
79 FE_INEXACT);
80 EXPECT_FP_EQ_WITH_EXCEPTION(T(1.0), func(T(0.715), FP_INT_UPWARD, 2U),
81 FE_INEXACT);
82 EXPECT_FP_EQ_WITH_EXCEPTION(T(-0.0), func(T(-0.715), FP_INT_UPWARD, 1U),
83 FE_INEXACT);
84 EXPECT_FP_EQ_WITH_EXCEPTION(T(2.0), func(T(1.3), FP_INT_UPWARD, 3U),
85 FE_INEXACT);
86 EXPECT_FP_EQ_WITH_EXCEPTION(T(-1.0), func(T(-1.3), FP_INT_UPWARD, 1U),
87 FE_INEXACT);
88 EXPECT_FP_EQ_WITH_EXCEPTION(T(2.0), func(T(1.5), FP_INT_UPWARD, 3U),
89 FE_INEXACT);
90 EXPECT_FP_EQ_WITH_EXCEPTION(T(-1.0), func(T(-1.5), FP_INT_UPWARD, 1U),
91 FE_INEXACT);
92 EXPECT_FP_EQ_WITH_EXCEPTION(T(2.0), func(T(1.75), FP_INT_UPWARD, 3U),
93 FE_INEXACT);
94 EXPECT_FP_EQ_WITH_EXCEPTION(T(-1.0), func(T(-1.75), FP_INT_UPWARD, 1U),
95 FE_INEXACT);
96 EXPECT_FP_EQ_WITH_EXCEPTION(T(11.0), func(T(10.32), FP_INT_UPWARD, 5U),
97 FE_INEXACT);
98 EXPECT_FP_EQ_WITH_EXCEPTION(T(-10.0), func(T(-10.32), FP_INT_UPWARD, 5U),
99 FE_INEXACT);
100 EXPECT_FP_EQ_WITH_EXCEPTION(T(11.0), func(T(10.65), FP_INT_UPWARD, 5U),
101 FE_INEXACT);
102 EXPECT_FP_EQ_WITH_EXCEPTION(T(-10.0), func(T(-10.65), FP_INT_UPWARD, 5U),
103 FE_INEXACT);
104 EXPECT_FP_EQ_WITH_EXCEPTION(T(1235.0), func(T(1234.38), FP_INT_UPWARD, 12U),
105 FE_INEXACT);
106 EXPECT_FP_EQ_WITH_EXCEPTION(
107 T(-1234.0), func(T(-1234.38), FP_INT_UPWARD, 12U), FE_INEXACT);
108 EXPECT_FP_EQ_WITH_EXCEPTION(T(1235.0), func(T(1234.96), FP_INT_UPWARD, 12U),
109 FE_INEXACT);
110 EXPECT_FP_EQ_WITH_EXCEPTION(
111 T(-1234.0), func(T(-1234.96), FP_INT_UPWARD, 12U), FE_INEXACT);
112 }
113
114 void testFractionsUpwardOutsideRange(FromfpxFunc func) {
115 EXPECT_FP_EQ_WITH_EXCEPTION(aNaN, func(T(0.5), FP_INT_UPWARD, 1U),
116 FE_INVALID);
117 EXPECT_FP_EQ_WITH_EXCEPTION(aNaN, func(T(0.115), FP_INT_UPWARD, 1U),
118 FE_INVALID);
119 EXPECT_FP_EQ_WITH_EXCEPTION(aNaN, func(T(0.715), FP_INT_UPWARD, 1U),
120 FE_INVALID);
121 EXPECT_FP_EQ_WITH_EXCEPTION(aNaN, func(T(1.3), FP_INT_UPWARD, 2U),
122 FE_INVALID);
123 EXPECT_FP_EQ_WITH_EXCEPTION(aNaN, func(T(1.5), FP_INT_UPWARD, 2U),
124 FE_INVALID);
125 EXPECT_FP_EQ_WITH_EXCEPTION(aNaN, func(T(1.75), FP_INT_UPWARD, 2U),
126 FE_INVALID);
127 EXPECT_FP_EQ_WITH_EXCEPTION(aNaN, func(T(10.32), FP_INT_UPWARD, 4U),
128 FE_INVALID);
129 EXPECT_FP_EQ_WITH_EXCEPTION(aNaN, func(T(-10.32), FP_INT_UPWARD, 4U),
130 FE_INVALID);
131 EXPECT_FP_EQ_WITH_EXCEPTION(aNaN, func(T(10.65), FP_INT_UPWARD, 4U),
132 FE_INVALID);
133 EXPECT_FP_EQ_WITH_EXCEPTION(aNaN, func(T(-10.65), FP_INT_UPWARD, 4U),
134 FE_INVALID);
135 EXPECT_FP_EQ_WITH_EXCEPTION(aNaN, func(T(1234.38), FP_INT_UPWARD, 11U),
136 FE_INVALID);
137 EXPECT_FP_EQ_WITH_EXCEPTION(aNaN, func(T(-1234.38), FP_INT_UPWARD, 11U),
138 FE_INVALID);
139 EXPECT_FP_EQ_WITH_EXCEPTION(aNaN, func(T(1234.96), FP_INT_UPWARD, 11U),
140 FE_INVALID);
141 EXPECT_FP_EQ_WITH_EXCEPTION(aNaN, func(T(-1234.96), FP_INT_UPWARD, 11U),
142 FE_INVALID);
143 }
144
145 void testFractionsDownwardWithinRange(FromfpxFunc func) {
146 EXPECT_FP_EQ_WITH_EXCEPTION(T(0.0), func(T(0.5), FP_INT_DOWNWARD, 1U),
147 FE_INEXACT);
148 EXPECT_FP_EQ_WITH_EXCEPTION(T(-1.0), func(T(-0.5), FP_INT_DOWNWARD, 1U),
149 FE_INEXACT);
150 EXPECT_FP_EQ_WITH_EXCEPTION(T(0.0), func(T(0.115), FP_INT_DOWNWARD, 1U),
151 FE_INEXACT);
152 EXPECT_FP_EQ_WITH_EXCEPTION(T(-1.0), func(T(-0.115), FP_INT_DOWNWARD, 1U),
153 FE_INEXACT);
154 EXPECT_FP_EQ_WITH_EXCEPTION(T(0.0), func(T(0.715), FP_INT_DOWNWARD, 1U),
155 FE_INEXACT);
156 EXPECT_FP_EQ_WITH_EXCEPTION(T(-1.0), func(T(-0.715), FP_INT_DOWNWARD, 1U),
157 FE_INEXACT);
158 EXPECT_FP_EQ_WITH_EXCEPTION(T(1.0), func(T(1.3), FP_INT_DOWNWARD, 2U),
159 FE_INEXACT);
160 EXPECT_FP_EQ_WITH_EXCEPTION(T(-2.0), func(T(-1.3), FP_INT_DOWNWARD, 2U),
161 FE_INEXACT);
162 EXPECT_FP_EQ_WITH_EXCEPTION(T(1.0), func(T(1.5), FP_INT_DOWNWARD, 2U),
163 FE_INEXACT);
164 EXPECT_FP_EQ_WITH_EXCEPTION(T(-2.0), func(T(-1.5), FP_INT_DOWNWARD, 2U),
165 FE_INEXACT);
166 EXPECT_FP_EQ_WITH_EXCEPTION(T(1.0), func(T(1.75), FP_INT_DOWNWARD, 2U),
167 FE_INEXACT);
168 EXPECT_FP_EQ_WITH_EXCEPTION(T(-2.0), func(T(-1.75), FP_INT_DOWNWARD, 2U),
169 FE_INEXACT);
170 EXPECT_FP_EQ_WITH_EXCEPTION(T(10.0), func(T(10.32), FP_INT_DOWNWARD, 5U),
171 FE_INEXACT);
172 EXPECT_FP_EQ_WITH_EXCEPTION(T(-11.0), func(T(-10.32), FP_INT_DOWNWARD, 5U),
173 FE_INEXACT);
174 EXPECT_FP_EQ_WITH_EXCEPTION(T(10.0), func(T(10.65), FP_INT_DOWNWARD, 5U),
175 FE_INEXACT);
176 EXPECT_FP_EQ_WITH_EXCEPTION(T(-11.0), func(T(-10.65), FP_INT_DOWNWARD, 5U),
177 FE_INEXACT);
178 EXPECT_FP_EQ_WITH_EXCEPTION(
179 T(1234.0), func(T(1234.38), FP_INT_DOWNWARD, 12U), FE_INEXACT);
180 EXPECT_FP_EQ_WITH_EXCEPTION(
181 T(-1235.0), func(T(-1234.38), FP_INT_DOWNWARD, 12U), FE_INEXACT);
182 EXPECT_FP_EQ_WITH_EXCEPTION(
183 T(1234.0), func(T(1234.96), FP_INT_DOWNWARD, 12U), FE_INEXACT);
184 EXPECT_FP_EQ_WITH_EXCEPTION(
185 T(-1235.0), func(T(-1234.96), FP_INT_DOWNWARD, 12U), FE_INEXACT);
186 }
187
188 void testFractionsDownwardOutsideRange(FromfpxFunc func) {
189 EXPECT_FP_EQ_WITH_EXCEPTION(aNaN, func(T(1.3), FP_INT_DOWNWARD, 1U),
190 FE_INVALID);
191 EXPECT_FP_EQ_WITH_EXCEPTION(aNaN, func(T(-1.3), FP_INT_DOWNWARD, 1U),
192 FE_INVALID);
193 EXPECT_FP_EQ_WITH_EXCEPTION(aNaN, func(T(1.5), FP_INT_DOWNWARD, 1U),
194 FE_INVALID);
195 EXPECT_FP_EQ_WITH_EXCEPTION(aNaN, func(T(-1.5), FP_INT_DOWNWARD, 1U),
196 FE_INVALID);
197 EXPECT_FP_EQ_WITH_EXCEPTION(aNaN, func(T(1.75), FP_INT_DOWNWARD, 1U),
198 FE_INVALID);
199 EXPECT_FP_EQ_WITH_EXCEPTION(aNaN, func(T(-1.75), FP_INT_DOWNWARD, 1U),
200 FE_INVALID);
201 EXPECT_FP_EQ_WITH_EXCEPTION(aNaN, func(T(10.32), FP_INT_DOWNWARD, 4U),
202 FE_INVALID);
203 EXPECT_FP_EQ_WITH_EXCEPTION(aNaN, func(T(-10.32), FP_INT_DOWNWARD, 4U),
204 FE_INVALID);
205 EXPECT_FP_EQ_WITH_EXCEPTION(aNaN, func(T(10.65), FP_INT_DOWNWARD, 4U),
206 FE_INVALID);
207 EXPECT_FP_EQ_WITH_EXCEPTION(aNaN, func(T(-10.65), FP_INT_DOWNWARD, 4U),
208 FE_INVALID);
209 EXPECT_FP_EQ_WITH_EXCEPTION(aNaN, func(T(1234.38), FP_INT_DOWNWARD, 11U),
210 FE_INVALID);
211 EXPECT_FP_EQ_WITH_EXCEPTION(aNaN, func(T(-1234.38), FP_INT_DOWNWARD, 11U),
212 FE_INVALID);
213 EXPECT_FP_EQ_WITH_EXCEPTION(aNaN, func(T(1234.96), FP_INT_DOWNWARD, 11U),
214 FE_INVALID);
215 EXPECT_FP_EQ_WITH_EXCEPTION(aNaN, func(T(-1234.96), FP_INT_DOWNWARD, 11U),
216 FE_INVALID);
217 }
218
219 void testFractionsTowardZeroWithinRange(FromfpxFunc func) {
220 EXPECT_FP_EQ_WITH_EXCEPTION(T(0.0), func(T(0.5), FP_INT_TOWARDZERO, 1U),
221 FE_INEXACT);
222 EXPECT_FP_EQ_WITH_EXCEPTION(T(-0.0), func(T(-0.5), FP_INT_TOWARDZERO, 1U),
223 FE_INEXACT);
224 EXPECT_FP_EQ_WITH_EXCEPTION(T(0.0), func(T(0.115), FP_INT_TOWARDZERO, 1U),
225 FE_INEXACT);
226 EXPECT_FP_EQ_WITH_EXCEPTION(T(-0.0), func(T(-0.115), FP_INT_TOWARDZERO, 1U),
227 FE_INEXACT);
228 EXPECT_FP_EQ_WITH_EXCEPTION(T(0.0), func(T(0.715), FP_INT_TOWARDZERO, 1U),
229 FE_INEXACT);
230 EXPECT_FP_EQ_WITH_EXCEPTION(T(-0.0), func(T(-0.715), FP_INT_TOWARDZERO, 1U),
231 FE_INEXACT);
232 EXPECT_FP_EQ_WITH_EXCEPTION(T(1.0), func(T(1.3), FP_INT_TOWARDZERO, 2U),
233 FE_INEXACT);
234 EXPECT_FP_EQ_WITH_EXCEPTION(T(-1.0), func(T(-1.3), FP_INT_TOWARDZERO, 1U),
235 FE_INEXACT);
236 EXPECT_FP_EQ_WITH_EXCEPTION(T(1.0), func(T(1.5), FP_INT_TOWARDZERO, 2U),
237 FE_INEXACT);
238 EXPECT_FP_EQ_WITH_EXCEPTION(T(-1.0), func(T(-1.5), FP_INT_TOWARDZERO, 1U),
239 FE_INEXACT);
240 EXPECT_FP_EQ_WITH_EXCEPTION(T(1.0), func(T(1.75), FP_INT_TOWARDZERO, 2U),
241 FE_INEXACT);
242 EXPECT_FP_EQ_WITH_EXCEPTION(T(-1.0), func(T(-1.75), FP_INT_TOWARDZERO, 1U),
243 FE_INEXACT);
244 EXPECT_FP_EQ_WITH_EXCEPTION(T(10.0), func(T(10.32), FP_INT_TOWARDZERO, 5U),
245 FE_INEXACT);
246 EXPECT_FP_EQ_WITH_EXCEPTION(
247 T(-10.0), func(T(-10.32), FP_INT_TOWARDZERO, 5U), FE_INEXACT);
248 EXPECT_FP_EQ_WITH_EXCEPTION(T(10.0), func(T(10.65), FP_INT_TOWARDZERO, 5U),
249 FE_INEXACT);
250 EXPECT_FP_EQ_WITH_EXCEPTION(
251 T(-10.0), func(T(-10.65), FP_INT_TOWARDZERO, 5U), FE_INEXACT);
252 EXPECT_FP_EQ_WITH_EXCEPTION(
253 T(1234.0), func(T(1234.38), FP_INT_TOWARDZERO, 12U), FE_INEXACT);
254 EXPECT_FP_EQ_WITH_EXCEPTION(
255 T(-1234.0), func(T(-1234.38), FP_INT_TOWARDZERO, 12U), FE_INEXACT);
256 EXPECT_FP_EQ_WITH_EXCEPTION(
257 T(1234.0), func(T(1234.96), FP_INT_TOWARDZERO, 12U), FE_INEXACT);
258 EXPECT_FP_EQ_WITH_EXCEPTION(
259 T(-1234.0), func(T(-1234.96), FP_INT_TOWARDZERO, 12U), FE_INEXACT);
260 }
261
262 void testFractionsTowardZeroOutsideRange(FromfpxFunc func) {
263 EXPECT_FP_EQ_WITH_EXCEPTION(aNaN, func(T(1.3), FP_INT_TOWARDZERO, 1U),
264 FE_INVALID);
265 EXPECT_FP_EQ_WITH_EXCEPTION(aNaN, func(T(1.5), FP_INT_TOWARDZERO, 1U),
266 FE_INVALID);
267 EXPECT_FP_EQ_WITH_EXCEPTION(aNaN, func(T(1.75), FP_INT_TOWARDZERO, 1U),
268 FE_INVALID);
269 EXPECT_FP_EQ_WITH_EXCEPTION(aNaN, func(T(10.32), FP_INT_TOWARDZERO, 4U),
270 FE_INVALID);
271 EXPECT_FP_EQ_WITH_EXCEPTION(aNaN, func(T(-10.32), FP_INT_TOWARDZERO, 4U),
272 FE_INVALID);
273 EXPECT_FP_EQ_WITH_EXCEPTION(aNaN, func(T(10.65), FP_INT_TOWARDZERO, 4U),
274 FE_INVALID);
275 EXPECT_FP_EQ_WITH_EXCEPTION(aNaN, func(T(-10.65), FP_INT_TOWARDZERO, 4U),
276 FE_INVALID);
277 EXPECT_FP_EQ_WITH_EXCEPTION(aNaN, func(T(1234.38), FP_INT_TOWARDZERO, 11U),
278 FE_INVALID);
279 EXPECT_FP_EQ_WITH_EXCEPTION(aNaN, func(T(-1234.38), FP_INT_TOWARDZERO, 11U),
280 FE_INVALID);
281 EXPECT_FP_EQ_WITH_EXCEPTION(aNaN, func(T(1234.96), FP_INT_TOWARDZERO, 11U),
282 FE_INVALID);
283 EXPECT_FP_EQ_WITH_EXCEPTION(aNaN, func(T(-1234.96), FP_INT_TOWARDZERO, 11U),
284 FE_INVALID);
285 }
286
287 void testFractionsToNearestFromZeroWithinRange(FromfpxFunc func) {
288 EXPECT_FP_EQ_WITH_EXCEPTION(
289 T(1.0), func(T(0.5), FP_INT_TONEARESTFROMZERO, 2U), FE_INEXACT);
290 EXPECT_FP_EQ_WITH_EXCEPTION(
291 T(-1.0), func(T(-0.5), FP_INT_TONEARESTFROMZERO, 1U), FE_INEXACT);
292 EXPECT_FP_EQ_WITH_EXCEPTION(
293 T(0.0), func(T(0.115), FP_INT_TONEARESTFROMZERO, 1U), FE_INEXACT);
294 EXPECT_FP_EQ_WITH_EXCEPTION(
295 T(-0.0), func(T(-0.115), FP_INT_TONEARESTFROMZERO, 1U), FE_INEXACT);
296 EXPECT_FP_EQ_WITH_EXCEPTION(
297 T(1.0), func(T(0.715), FP_INT_TONEARESTFROMZERO, 2U), FE_INEXACT);
298 EXPECT_FP_EQ_WITH_EXCEPTION(
299 T(-1.0), func(T(-0.715), FP_INT_TONEARESTFROMZERO, 1U), FE_INEXACT);
300 EXPECT_FP_EQ_WITH_EXCEPTION(
301 T(1.0), func(T(1.3), FP_INT_TONEARESTFROMZERO, 2U), FE_INEXACT);
302 EXPECT_FP_EQ_WITH_EXCEPTION(
303 T(-1.0), func(T(-1.3), FP_INT_TONEARESTFROMZERO, 1U), FE_INEXACT);
304 EXPECT_FP_EQ_WITH_EXCEPTION(
305 T(2.0), func(T(1.5), FP_INT_TONEARESTFROMZERO, 3U), FE_INEXACT);
306 EXPECT_FP_EQ_WITH_EXCEPTION(
307 T(-2.0), func(T(-1.5), FP_INT_TONEARESTFROMZERO, 2U), FE_INEXACT);
308 EXPECT_FP_EQ_WITH_EXCEPTION(
309 T(2.0), func(T(1.75), FP_INT_TONEARESTFROMZERO, 3U), FE_INEXACT);
310 EXPECT_FP_EQ_WITH_EXCEPTION(
311 T(-2.0), func(T(-1.75), FP_INT_TONEARESTFROMZERO, 2U), FE_INEXACT);
312 EXPECT_FP_EQ_WITH_EXCEPTION(
313 T(10.0), func(T(10.32), FP_INT_TONEARESTFROMZERO, 5U), FE_INEXACT);
314 EXPECT_FP_EQ_WITH_EXCEPTION(
315 T(-10.0), func(T(-10.32), FP_INT_TONEARESTFROMZERO, 5U), FE_INEXACT);
316 EXPECT_FP_EQ_WITH_EXCEPTION(
317 T(11.0), func(T(10.65), FP_INT_TONEARESTFROMZERO, 5U), FE_INEXACT);
318 EXPECT_FP_EQ_WITH_EXCEPTION(
319 T(-11.0), func(T(-10.65), FP_INT_TONEARESTFROMZERO, 5U), FE_INEXACT);
320 EXPECT_FP_EQ_WITH_EXCEPTION(
321 T(1234.0), func(T(1234.38), FP_INT_TONEARESTFROMZERO, 12U), FE_INEXACT);
322 EXPECT_FP_EQ_WITH_EXCEPTION(
323 T(-1234.0), func(T(-1234.38), FP_INT_TONEARESTFROMZERO, 12U),
324 FE_INEXACT);
325 EXPECT_FP_EQ_WITH_EXCEPTION(
326 T(1235.0), func(T(1234.96), FP_INT_TONEARESTFROMZERO, 12U), FE_INEXACT);
327 EXPECT_FP_EQ_WITH_EXCEPTION(
328 T(-1235.0), func(T(-1234.96), FP_INT_TONEARESTFROMZERO, 12U),
329 FE_INEXACT);
330 }
331
332 void testFractionsToNearestFromZeroOutsideRange(FromfpxFunc func) {
333 EXPECT_FP_EQ_WITH_EXCEPTION(
334 aNaN, func(T(0.5), FP_INT_TONEARESTFROMZERO, 1U), FE_INVALID);
335 EXPECT_FP_EQ_WITH_EXCEPTION(
336 aNaN, func(T(0.715), FP_INT_TONEARESTFROMZERO, 1U), FE_INVALID);
337 EXPECT_FP_EQ_WITH_EXCEPTION(
338 aNaN, func(T(1.3), FP_INT_TONEARESTFROMZERO, 1U), FE_INVALID);
339 EXPECT_FP_EQ_WITH_EXCEPTION(
340 aNaN, func(T(1.5), FP_INT_TONEARESTFROMZERO, 2U), FE_INVALID);
341 EXPECT_FP_EQ_WITH_EXCEPTION(
342 aNaN, func(T(-1.5), FP_INT_TONEARESTFROMZERO, 1U), FE_INVALID);
343 EXPECT_FP_EQ_WITH_EXCEPTION(
344 aNaN, func(T(1.75), FP_INT_TONEARESTFROMZERO, 2U), FE_INVALID);
345 EXPECT_FP_EQ_WITH_EXCEPTION(
346 aNaN, func(T(-1.75), FP_INT_TONEARESTFROMZERO, 1U), FE_INVALID);
347 EXPECT_FP_EQ_WITH_EXCEPTION(
348 aNaN, func(T(10.32), FP_INT_TONEARESTFROMZERO, 4U), FE_INVALID);
349 EXPECT_FP_EQ_WITH_EXCEPTION(
350 aNaN, func(T(-10.32), FP_INT_TONEARESTFROMZERO, 4U), FE_INVALID);
351 EXPECT_FP_EQ_WITH_EXCEPTION(
352 aNaN, func(T(10.65), FP_INT_TONEARESTFROMZERO, 4U), FE_INVALID);
353 EXPECT_FP_EQ_WITH_EXCEPTION(
354 aNaN, func(T(-10.65), FP_INT_TONEARESTFROMZERO, 4U), FE_INVALID);
355 EXPECT_FP_EQ_WITH_EXCEPTION(
356 aNaN, func(T(1234.38), FP_INT_TONEARESTFROMZERO, 11U), FE_INVALID);
357 EXPECT_FP_EQ_WITH_EXCEPTION(
358 aNaN, func(T(-1234.38), FP_INT_TONEARESTFROMZERO, 11U), FE_INVALID);
359 EXPECT_FP_EQ_WITH_EXCEPTION(
360 aNaN, func(T(1234.96), FP_INT_TONEARESTFROMZERO, 11U), FE_INVALID);
361 EXPECT_FP_EQ_WITH_EXCEPTION(
362 aNaN, func(T(-1234.96), FP_INT_TONEARESTFROMZERO, 11U), FE_INVALID);
363 }
364
365 void testFractionsToNearestWithinRange(FromfpxFunc func) {
366 EXPECT_FP_EQ_WITH_EXCEPTION(T(0.0), func(T(0.5), FP_INT_TONEAREST, 1U),
367 FE_INEXACT);
368 EXPECT_FP_EQ_WITH_EXCEPTION(T(-0.0), func(T(-0.5), FP_INT_TONEAREST, 1U),
369 FE_INEXACT);
370 EXPECT_FP_EQ_WITH_EXCEPTION(T(0.0), func(T(0.115), FP_INT_TONEAREST, 1U),
371 FE_INEXACT);
372 EXPECT_FP_EQ_WITH_EXCEPTION(T(-0.0), func(T(-0.115), FP_INT_TONEAREST, 1U),
373 FE_INEXACT);
374 EXPECT_FP_EQ_WITH_EXCEPTION(T(1.0), func(T(0.715), FP_INT_TONEAREST, 2U),
375 FE_INEXACT);
376 EXPECT_FP_EQ_WITH_EXCEPTION(T(-1.0), func(T(-0.715), FP_INT_TONEAREST, 1U),
377 FE_INEXACT);
378 EXPECT_FP_EQ_WITH_EXCEPTION(T(1.0), func(T(1.3), FP_INT_TONEAREST, 2U),
379 FE_INEXACT);
380 EXPECT_FP_EQ_WITH_EXCEPTION(T(-1.0), func(T(-1.3), FP_INT_TONEAREST, 1U),
381 FE_INEXACT);
382 EXPECT_FP_EQ_WITH_EXCEPTION(T(2.0), func(T(1.5), FP_INT_TONEAREST, 3U),
383 FE_INEXACT);
384 EXPECT_FP_EQ_WITH_EXCEPTION(T(-2.0), func(T(-1.5), FP_INT_TONEAREST, 2U),
385 FE_INEXACT);
386 EXPECT_FP_EQ_WITH_EXCEPTION(T(2.0), func(T(1.75), FP_INT_TONEAREST, 3U),
387 FE_INEXACT);
388 EXPECT_FP_EQ_WITH_EXCEPTION(T(-2.0), func(T(-1.75), FP_INT_TONEAREST, 2U),
389 FE_INEXACT);
390 EXPECT_FP_EQ_WITH_EXCEPTION(T(10.0), func(T(10.32), FP_INT_TONEAREST, 5U),
391 FE_INEXACT);
392 EXPECT_FP_EQ_WITH_EXCEPTION(T(-10.0), func(T(-10.32), FP_INT_TONEAREST, 5U),
393 FE_INEXACT);
394 EXPECT_FP_EQ_WITH_EXCEPTION(T(11.0), func(T(10.65), FP_INT_TONEAREST, 5U),
395 FE_INEXACT);
396 EXPECT_FP_EQ_WITH_EXCEPTION(T(-11.0), func(T(-10.65), FP_INT_TONEAREST, 5U),
397 FE_INEXACT);
398 EXPECT_FP_EQ_WITH_EXCEPTION(
399 T(1234.0), func(T(1234.38), FP_INT_TONEAREST, 12U), FE_INEXACT);
400 EXPECT_FP_EQ_WITH_EXCEPTION(
401 T(-1234.0), func(T(-1234.38), FP_INT_TONEAREST, 12U), FE_INEXACT);
402 EXPECT_FP_EQ_WITH_EXCEPTION(
403 T(1235.0), func(T(1234.96), FP_INT_TONEAREST, 12U), FE_INEXACT);
404 EXPECT_FP_EQ_WITH_EXCEPTION(
405 T(-1235.0), func(T(-1234.96), FP_INT_TONEAREST, 12U), FE_INEXACT);
406
407 EXPECT_FP_EQ_WITH_EXCEPTION(T(2.0), func(T(2.3), FP_INT_TONEAREST, 3U),
408 FE_INEXACT);
409 EXPECT_FP_EQ_WITH_EXCEPTION(T(-2.0), func(T(-2.3), FP_INT_TONEAREST, 2U),
410 FE_INEXACT);
411 EXPECT_FP_EQ_WITH_EXCEPTION(T(2.0), func(T(2.5), FP_INT_TONEAREST, 3U),
412 FE_INEXACT);
413 EXPECT_FP_EQ_WITH_EXCEPTION(T(-2.0), func(T(-2.5), FP_INT_TONEAREST, 2U),
414 FE_INEXACT);
415 EXPECT_FP_EQ_WITH_EXCEPTION(T(3.0), func(T(2.75), FP_INT_TONEAREST, 3U),
416 FE_INEXACT);
417 EXPECT_FP_EQ_WITH_EXCEPTION(T(-3.0), func(T(-2.75), FP_INT_TONEAREST, 3U),
418 FE_INEXACT);
419 EXPECT_FP_EQ_WITH_EXCEPTION(T(5.0), func(T(5.3), FP_INT_TONEAREST, 4U),
420 FE_INEXACT);
421 EXPECT_FP_EQ_WITH_EXCEPTION(T(-5.0), func(T(-5.3), FP_INT_TONEAREST, 4U),
422 FE_INEXACT);
423 EXPECT_FP_EQ_WITH_EXCEPTION(T(6.0), func(T(5.5), FP_INT_TONEAREST, 4U),
424 FE_INEXACT);
425 EXPECT_FP_EQ_WITH_EXCEPTION(T(-6.0), func(T(-5.5), FP_INT_TONEAREST, 4U),
426 FE_INEXACT);
427 EXPECT_FP_EQ_WITH_EXCEPTION(T(6.0), func(T(5.75), FP_INT_TONEAREST, 4U),
428 FE_INEXACT);
429 EXPECT_FP_EQ_WITH_EXCEPTION(T(-6.0), func(T(-5.75), FP_INT_TONEAREST, 4U),
430 FE_INEXACT);
431 }
432
433 void testFractionsToNearestOutsideRange(FromfpxFunc func) {
434 EXPECT_FP_EQ_WITH_EXCEPTION(aNaN, func(T(0.715), FP_INT_TONEAREST, 1U),
435 FE_INVALID);
436 EXPECT_FP_EQ_WITH_EXCEPTION(aNaN, func(T(1.3), FP_INT_TONEAREST, 1U),
437 FE_INVALID);
438 EXPECT_FP_EQ_WITH_EXCEPTION(aNaN, func(T(1.5), FP_INT_TONEAREST, 2U),
439 FE_INVALID);
440 EXPECT_FP_EQ_WITH_EXCEPTION(aNaN, func(T(-1.5), FP_INT_TONEAREST, 1U),
441 FE_INVALID);
442 EXPECT_FP_EQ_WITH_EXCEPTION(aNaN, func(T(1.75), FP_INT_TONEAREST, 2U),
443 FE_INVALID);
444 EXPECT_FP_EQ_WITH_EXCEPTION(aNaN, func(T(-1.75), FP_INT_TONEAREST, 1U),
445 FE_INVALID);
446 EXPECT_FP_EQ_WITH_EXCEPTION(aNaN, func(T(10.32), FP_INT_TONEAREST, 4U),
447 FE_INVALID);
448 EXPECT_FP_EQ_WITH_EXCEPTION(aNaN, func(T(-10.32), FP_INT_TONEAREST, 4U),
449 FE_INVALID);
450 EXPECT_FP_EQ_WITH_EXCEPTION(aNaN, func(T(10.65), FP_INT_TONEAREST, 4U),
451 FE_INVALID);
452 EXPECT_FP_EQ_WITH_EXCEPTION(aNaN, func(T(-10.65), FP_INT_TONEAREST, 4U),
453 FE_INVALID);
454 EXPECT_FP_EQ_WITH_EXCEPTION(aNaN, func(T(1234.38), FP_INT_TONEAREST, 11U),
455 FE_INVALID);
456 EXPECT_FP_EQ_WITH_EXCEPTION(aNaN, func(T(-1234.38), FP_INT_TONEAREST, 11U),
457 FE_INVALID);
458 EXPECT_FP_EQ_WITH_EXCEPTION(aNaN, func(T(1234.96), FP_INT_TONEAREST, 11U),
459 FE_INVALID);
460 EXPECT_FP_EQ_WITH_EXCEPTION(aNaN, func(T(-1234.96), FP_INT_TONEAREST, 11U),
461 FE_INVALID);
462
463 EXPECT_FP_EQ_WITH_EXCEPTION(aNaN, func(T(2.3), FP_INT_TONEAREST, 2U),
464 FE_INVALID);
465 EXPECT_FP_EQ_WITH_EXCEPTION(aNaN, func(T(-2.3), FP_INT_TONEAREST, 1U),
466 FE_INVALID);
467 EXPECT_FP_EQ_WITH_EXCEPTION(aNaN, func(T(2.5), FP_INT_TONEAREST, 2U),
468 FE_INVALID);
469 EXPECT_FP_EQ_WITH_EXCEPTION(aNaN, func(T(-2.5), FP_INT_TONEAREST, 1U),
470 FE_INVALID);
471 EXPECT_FP_EQ_WITH_EXCEPTION(aNaN, func(T(2.75), FP_INT_TONEAREST, 2U),
472 FE_INVALID);
473 EXPECT_FP_EQ_WITH_EXCEPTION(aNaN, func(T(-2.75), FP_INT_TONEAREST, 2U),
474 FE_INVALID);
475 EXPECT_FP_EQ_WITH_EXCEPTION(aNaN, func(T(5.3), FP_INT_TONEAREST, 3U),
476 FE_INVALID);
477 EXPECT_FP_EQ_WITH_EXCEPTION(aNaN, func(T(-5.3), FP_INT_TONEAREST, 3U),
478 FE_INVALID);
479 EXPECT_FP_EQ_WITH_EXCEPTION(aNaN, func(T(5.5), FP_INT_TONEAREST, 3U),
480 FE_INVALID);
481 EXPECT_FP_EQ_WITH_EXCEPTION(aNaN, func(T(-5.5), FP_INT_TONEAREST, 3U),
482 FE_INVALID);
483 EXPECT_FP_EQ_WITH_EXCEPTION(aNaN, func(T(5.75), FP_INT_TONEAREST, 3U),
484 FE_INVALID);
485 EXPECT_FP_EQ_WITH_EXCEPTION(aNaN, func(T(-5.75), FP_INT_TONEAREST, 3U),
486 FE_INVALID);
487 }
488
489 void testFractionsToNearestFallbackWithinRange(FromfpxFunc func) {
490 EXPECT_FP_EQ_WITH_EXCEPTION(
491 T(0.0), func(T(0.5), UNKNOWN_MATH_ROUNDING_DIRECTION, 1U), FE_INEXACT);
492 EXPECT_FP_EQ_WITH_EXCEPTION(
493 T(-0.0), func(T(-0.5), UNKNOWN_MATH_ROUNDING_DIRECTION, 1U),
494 FE_INEXACT);
495 EXPECT_FP_EQ_WITH_EXCEPTION(
496 T(0.0), func(T(0.115), UNKNOWN_MATH_ROUNDING_DIRECTION, 1U),
497 FE_INEXACT);
498 EXPECT_FP_EQ_WITH_EXCEPTION(
499 T(-0.0), func(T(-0.115), UNKNOWN_MATH_ROUNDING_DIRECTION, 1U),
500 FE_INEXACT);
501 EXPECT_FP_EQ_WITH_EXCEPTION(
502 T(1.0), func(T(0.715), UNKNOWN_MATH_ROUNDING_DIRECTION, 2U),
503 FE_INEXACT);
504 EXPECT_FP_EQ_WITH_EXCEPTION(
505 T(-1.0), func(T(-0.715), UNKNOWN_MATH_ROUNDING_DIRECTION, 1U),
506 FE_INEXACT);
507 EXPECT_FP_EQ_WITH_EXCEPTION(
508 T(1.0), func(T(1.3), UNKNOWN_MATH_ROUNDING_DIRECTION, 2U), FE_INEXACT);
509 EXPECT_FP_EQ_WITH_EXCEPTION(
510 T(-1.0), func(T(-1.3), UNKNOWN_MATH_ROUNDING_DIRECTION, 1U),
511 FE_INEXACT);
512 EXPECT_FP_EQ_WITH_EXCEPTION(
513 T(2.0), func(T(1.5), UNKNOWN_MATH_ROUNDING_DIRECTION, 3U), FE_INEXACT);
514 EXPECT_FP_EQ_WITH_EXCEPTION(
515 T(-2.0), func(T(-1.5), UNKNOWN_MATH_ROUNDING_DIRECTION, 2U),
516 FE_INEXACT);
517 EXPECT_FP_EQ_WITH_EXCEPTION(
518 T(2.0), func(T(1.75), UNKNOWN_MATH_ROUNDING_DIRECTION, 3U), FE_INEXACT);
519 EXPECT_FP_EQ_WITH_EXCEPTION(
520 T(-2.0), func(T(-1.75), UNKNOWN_MATH_ROUNDING_DIRECTION, 2U),
521 FE_INEXACT);
522 EXPECT_FP_EQ_WITH_EXCEPTION(
523 T(10.0), func(T(10.32), UNKNOWN_MATH_ROUNDING_DIRECTION, 5U),
524 FE_INEXACT);
525 EXPECT_FP_EQ_WITH_EXCEPTION(
526 T(-10.0), func(T(-10.32), UNKNOWN_MATH_ROUNDING_DIRECTION, 5U),
527 FE_INEXACT);
528 EXPECT_FP_EQ_WITH_EXCEPTION(
529 T(11.0), func(T(10.65), UNKNOWN_MATH_ROUNDING_DIRECTION, 5U),
530 FE_INEXACT);
531 EXPECT_FP_EQ_WITH_EXCEPTION(
532 T(-11.0), func(T(-10.65), UNKNOWN_MATH_ROUNDING_DIRECTION, 5U),
533 FE_INEXACT);
534 EXPECT_FP_EQ_WITH_EXCEPTION(
535 T(1234.0), func(T(1234.38), UNKNOWN_MATH_ROUNDING_DIRECTION, 12U),
536 FE_INEXACT);
537 EXPECT_FP_EQ_WITH_EXCEPTION(
538 T(-1234.0), func(T(-1234.38), UNKNOWN_MATH_ROUNDING_DIRECTION, 12U),
539 FE_INEXACT);
540 EXPECT_FP_EQ_WITH_EXCEPTION(
541 T(1235.0), func(T(1234.96), UNKNOWN_MATH_ROUNDING_DIRECTION, 12U),
542 FE_INEXACT);
543 EXPECT_FP_EQ_WITH_EXCEPTION(
544 T(-1235.0), func(T(-1234.96), UNKNOWN_MATH_ROUNDING_DIRECTION, 12U),
545 FE_INEXACT);
546
547 EXPECT_FP_EQ_WITH_EXCEPTION(
548 T(2.0), func(T(2.3), UNKNOWN_MATH_ROUNDING_DIRECTION, 3U), FE_INEXACT);
549 EXPECT_FP_EQ_WITH_EXCEPTION(
550 T(-2.0), func(T(-2.3), UNKNOWN_MATH_ROUNDING_DIRECTION, 2U),
551 FE_INEXACT);
552 EXPECT_FP_EQ_WITH_EXCEPTION(
553 T(2.0), func(T(2.5), UNKNOWN_MATH_ROUNDING_DIRECTION, 3U), FE_INEXACT);
554 EXPECT_FP_EQ_WITH_EXCEPTION(
555 T(-2.0), func(T(-2.5), UNKNOWN_MATH_ROUNDING_DIRECTION, 2U),
556 FE_INEXACT);
557 EXPECT_FP_EQ_WITH_EXCEPTION(
558 T(3.0), func(T(2.75), UNKNOWN_MATH_ROUNDING_DIRECTION, 3U), FE_INEXACT);
559 EXPECT_FP_EQ_WITH_EXCEPTION(
560 T(-3.0), func(T(-2.75), UNKNOWN_MATH_ROUNDING_DIRECTION, 3U),
561 FE_INEXACT);
562 EXPECT_FP_EQ_WITH_EXCEPTION(
563 T(5.0), func(T(5.3), UNKNOWN_MATH_ROUNDING_DIRECTION, 4U), FE_INEXACT);
564 EXPECT_FP_EQ_WITH_EXCEPTION(
565 T(-5.0), func(T(-5.3), UNKNOWN_MATH_ROUNDING_DIRECTION, 4U),
566 FE_INEXACT);
567 EXPECT_FP_EQ_WITH_EXCEPTION(
568 T(6.0), func(T(5.5), UNKNOWN_MATH_ROUNDING_DIRECTION, 4U), FE_INEXACT);
569 EXPECT_FP_EQ_WITH_EXCEPTION(
570 T(-6.0), func(T(-5.5), UNKNOWN_MATH_ROUNDING_DIRECTION, 4U),
571 FE_INEXACT);
572 EXPECT_FP_EQ_WITH_EXCEPTION(
573 T(6.0), func(T(5.75), UNKNOWN_MATH_ROUNDING_DIRECTION, 4U), FE_INEXACT);
574 EXPECT_FP_EQ_WITH_EXCEPTION(
575 T(-6.0), func(T(-5.75), UNKNOWN_MATH_ROUNDING_DIRECTION, 4U),
576 FE_INEXACT);
577 }
578
579 void testFractionsToNearestFallbackOutsideRange(FromfpxFunc func) {
580 EXPECT_FP_EQ_WITH_EXCEPTION(
581 aNaN, func(T(0.715), UNKNOWN_MATH_ROUNDING_DIRECTION, 1U), FE_INVALID);
582 EXPECT_FP_EQ_WITH_EXCEPTION(
583 aNaN, func(T(1.3), UNKNOWN_MATH_ROUNDING_DIRECTION, 1U), FE_INVALID);
584 EXPECT_FP_EQ_WITH_EXCEPTION(
585 aNaN, func(T(1.5), UNKNOWN_MATH_ROUNDING_DIRECTION, 2U), FE_INVALID);
586 EXPECT_FP_EQ_WITH_EXCEPTION(
587 aNaN, func(T(-1.5), UNKNOWN_MATH_ROUNDING_DIRECTION, 1U), FE_INVALID);
588 EXPECT_FP_EQ_WITH_EXCEPTION(
589 aNaN, func(T(1.75), UNKNOWN_MATH_ROUNDING_DIRECTION, 2U), FE_INVALID);
590 EXPECT_FP_EQ_WITH_EXCEPTION(
591 aNaN, func(T(-1.75), UNKNOWN_MATH_ROUNDING_DIRECTION, 1U), FE_INVALID);
592 EXPECT_FP_EQ_WITH_EXCEPTION(
593 aNaN, func(T(10.32), UNKNOWN_MATH_ROUNDING_DIRECTION, 4U), FE_INVALID);
594 EXPECT_FP_EQ_WITH_EXCEPTION(
595 aNaN, func(T(-10.32), UNKNOWN_MATH_ROUNDING_DIRECTION, 4U), FE_INVALID);
596 EXPECT_FP_EQ_WITH_EXCEPTION(
597 aNaN, func(T(10.65), UNKNOWN_MATH_ROUNDING_DIRECTION, 4U), FE_INVALID);
598 EXPECT_FP_EQ_WITH_EXCEPTION(
599 aNaN, func(T(-10.65), UNKNOWN_MATH_ROUNDING_DIRECTION, 4U), FE_INVALID);
600 EXPECT_FP_EQ_WITH_EXCEPTION(
601 aNaN, func(T(1234.38), UNKNOWN_MATH_ROUNDING_DIRECTION, 11U),
602 FE_INVALID);
603 EXPECT_FP_EQ_WITH_EXCEPTION(
604 aNaN, func(T(-1234.38), UNKNOWN_MATH_ROUNDING_DIRECTION, 11U),
605 FE_INVALID);
606 EXPECT_FP_EQ_WITH_EXCEPTION(
607 aNaN, func(T(1234.96), UNKNOWN_MATH_ROUNDING_DIRECTION, 11U),
608 FE_INVALID);
609 EXPECT_FP_EQ_WITH_EXCEPTION(
610 aNaN, func(T(-1234.96), UNKNOWN_MATH_ROUNDING_DIRECTION, 11U),
611 FE_INVALID);
612
613 EXPECT_FP_EQ_WITH_EXCEPTION(
614 aNaN, func(T(2.3), UNKNOWN_MATH_ROUNDING_DIRECTION, 2U), FE_INVALID);
615 EXPECT_FP_EQ_WITH_EXCEPTION(
616 aNaN, func(T(-2.3), UNKNOWN_MATH_ROUNDING_DIRECTION, 1U), FE_INVALID);
617 EXPECT_FP_EQ_WITH_EXCEPTION(
618 aNaN, func(T(2.5), UNKNOWN_MATH_ROUNDING_DIRECTION, 2U), FE_INVALID);
619 EXPECT_FP_EQ_WITH_EXCEPTION(
620 aNaN, func(T(-2.5), UNKNOWN_MATH_ROUNDING_DIRECTION, 1U), FE_INVALID);
621 EXPECT_FP_EQ_WITH_EXCEPTION(
622 aNaN, func(T(2.75), UNKNOWN_MATH_ROUNDING_DIRECTION, 2U), FE_INVALID);
623 EXPECT_FP_EQ_WITH_EXCEPTION(
624 aNaN, func(T(-2.75), UNKNOWN_MATH_ROUNDING_DIRECTION, 2U), FE_INVALID);
625 EXPECT_FP_EQ_WITH_EXCEPTION(
626 aNaN, func(T(5.3), UNKNOWN_MATH_ROUNDING_DIRECTION, 3U), FE_INVALID);
627 EXPECT_FP_EQ_WITH_EXCEPTION(
628 aNaN, func(T(-5.3), UNKNOWN_MATH_ROUNDING_DIRECTION, 3U), FE_INVALID);
629 EXPECT_FP_EQ_WITH_EXCEPTION(
630 aNaN, func(T(5.5), UNKNOWN_MATH_ROUNDING_DIRECTION, 3U), FE_INVALID);
631 EXPECT_FP_EQ_WITH_EXCEPTION(
632 aNaN, func(T(-5.5), UNKNOWN_MATH_ROUNDING_DIRECTION, 3U), FE_INVALID);
633 EXPECT_FP_EQ_WITH_EXCEPTION(
634 aNaN, func(T(5.75), UNKNOWN_MATH_ROUNDING_DIRECTION, 3U), FE_INVALID);
635 EXPECT_FP_EQ_WITH_EXCEPTION(
636 aNaN, func(T(-5.75), UNKNOWN_MATH_ROUNDING_DIRECTION, 3U), FE_INVALID);
637 }
638};
639
640#define LIST_FROMFPX_TESTS(T, func) \
641 using LlvmLibcFromfpxTest = FromfpxTestTemplate<T>; \
642 TEST_F(LlvmLibcFromfpxTest, SpecialNumbersNonzeroWidth) { \
643 testSpecialNumbersNonzeroWidth(&func); \
644 } \
645 TEST_F(LlvmLibcFromfpxTest, SpecialNumbersZeroWidth) { \
646 testSpecialNumbersZeroWidth(&func); \
647 } \
648 TEST_F(LlvmLibcFromfpxTest, RoundedNumbersWithinRange) { \
649 testRoundedNumbersWithinRange(&func); \
650 } \
651 TEST_F(LlvmLibcFromfpxTest, RoundedNumbersOutsideRange) { \
652 testRoundedNumbersOutsideRange(&func); \
653 } \
654 TEST_F(LlvmLibcFromfpxTest, FractionsUpwardWithinRange) { \
655 testFractionsUpwardWithinRange(&func); \
656 } \
657 TEST_F(LlvmLibcFromfpxTest, FractionsUpwardOutsideRange) { \
658 testFractionsUpwardOutsideRange(&func); \
659 } \
660 TEST_F(LlvmLibcFromfpxTest, FractionsDownwardWithinRange) { \
661 testFractionsDownwardWithinRange(&func); \
662 } \
663 TEST_F(LlvmLibcFromfpxTest, FractionsDownwardOutsideRange) { \
664 testFractionsDownwardOutsideRange(&func); \
665 } \
666 TEST_F(LlvmLibcFromfpxTest, FractionsTowardZeroWithinRange) { \
667 testFractionsTowardZeroWithinRange(&func); \
668 } \
669 TEST_F(LlvmLibcFromfpxTest, FractionsTowardZeroOutsideRange) { \
670 testFractionsTowardZeroOutsideRange(&func); \
671 } \
672 TEST_F(LlvmLibcFromfpxTest, FractionsToNearestFromZeroWithinRange) { \
673 testFractionsToNearestFromZeroWithinRange(&func); \
674 } \
675 TEST_F(LlvmLibcFromfpxTest, FractionsToNearestFromZeroOutsideRange) { \
676 testFractionsToNearestFromZeroOutsideRange(&func); \
677 } \
678 TEST_F(LlvmLibcFromfpxTest, FractionsToNearestWithinRange) { \
679 testFractionsToNearestWithinRange(&func); \
680 } \
681 TEST_F(LlvmLibcFromfpxTest, FractionsToNearestOutsideRange) { \
682 testFractionsToNearestOutsideRange(&func); \
683 } \
684 TEST_F(LlvmLibcFromfpxTest, FractionsToNearestFallbackWithinRange) { \
685 testFractionsToNearestFallbackWithinRange(&func); \
686 } \
687 TEST_F(LlvmLibcFromfpxTest, FractionsToNearestFallbackOutsideRange) { \
688 testFractionsToNearestFallbackOutsideRange(&func); \
689 }
690
691#endif // LIBC_TEST_SRC_MATH_SMOKE_FROMFPXTEST_H
692

source code of libc/test/src/math/smoke/FromfpxTest.h