@@ -26,11 +26,11 @@ using LIBC_NAMESPACE::Sign;
26
26
static constexpr int ROUNDING_MODES[4 ] = {FE_UPWARD, FE_DOWNWARD, FE_TOWARDZERO,
27
27
FE_TONEAREST};
28
28
29
- template <typename F, typename I , bool TestModes = false >
29
+ template <typename F, typename OutType , bool TestModes = false >
30
30
class RoundToIntegerTestTemplate
31
31
: public LIBC_NAMESPACE::testing::FEnvSafeTest {
32
32
public:
33
- typedef I (*RoundToIntegerFunc)(F);
33
+ typedef OutType (*RoundToIntegerFunc)(F);
34
34
35
35
private:
36
36
using FPBits = LIBC_NAMESPACE::fputil::FPBits<F>;
@@ -49,10 +49,11 @@ class RoundToIntegerTestTemplate
49
49
static constexpr StorageType MIN_SUBNORMAL =
50
50
FPBits::min_subnormal ().uintval();
51
51
52
- static constexpr I INTEGER_MIN = I(1 ) << (sizeof (I) * 8 - 1 );
53
- static constexpr I INTEGER_MAX = -(INTEGER_MIN + 1 );
52
+ static constexpr OutType INTEGER_MIN = OutType(1 )
53
+ << (sizeof (OutType) * 8 - 1 );
54
+ static constexpr OutType INTEGER_MAX = -(INTEGER_MIN + 1 );
54
55
55
- void test_one_input (RoundToIntegerFunc func, F input, I expected,
56
+ void test_one_input (RoundToIntegerFunc func, F input, OutType expected,
56
57
bool expectError) {
57
58
LIBC_NAMESPACE::libc_errno = 0 ;
58
59
LIBC_NAMESPACE::fputil::clear_except (FE_ALL_EXCEPT);
@@ -120,24 +121,24 @@ class RoundToIntegerTestTemplate
120
121
}
121
122
122
123
void do_round_numbers_test (RoundToIntegerFunc func) {
123
- test_one_input (func, zero, I (0 ), false );
124
- test_one_input (func, neg_zero, I (0 ), false );
125
- test_one_input (func, F (1.0 ), I (1 ), false );
126
- test_one_input (func, F (-1.0 ), I (-1 ), false );
127
- test_one_input (func, F (10.0 ), I (10 ), false );
128
- test_one_input (func, F (-10.0 ), I (-10 ), false );
129
- test_one_input (func, F (1234.0 ), I (1234 ), false );
130
- test_one_input (func, F (-1234.0 ), I (-1234 ), false );
124
+ test_one_input (func, zero, OutType (0 ), false );
125
+ test_one_input (func, neg_zero, OutType (0 ), false );
126
+ test_one_input (func, F (1.0 ), OutType (1 ), false );
127
+ test_one_input (func, F (-1.0 ), OutType (-1 ), false );
128
+ test_one_input (func, F (10.0 ), OutType (10 ), false );
129
+ test_one_input (func, F (-10.0 ), OutType (-10 ), false );
130
+ test_one_input (func, F (1234.0 ), OutType (1234 ), false );
131
+ test_one_input (func, F (-1234.0 ), OutType (-1234 ), false );
131
132
132
133
// The rest of this function compares with an equivalent MPFR function
133
134
// which rounds floating point numbers to long values. There is no MPFR
134
135
// function to round to long long or wider integer values. So, we will
135
- // the remaining tests only if the width of I less than equal to that of
136
- // long.
137
- if (sizeof (I ) > sizeof (long ))
136
+ // the remaining tests only if the width of OutType less than equal to that
137
+ // of long.
138
+ if (sizeof (OutType ) > sizeof (long ))
138
139
return ;
139
140
140
- constexpr int EXPONENT_LIMIT = sizeof (I ) * 8 - 1 ;
141
+ constexpr int EXPONENT_LIMIT = sizeof (OutType ) * 8 - 1 ;
141
142
constexpr int BIASED_EXPONENT_LIMIT = EXPONENT_LIMIT + FPBits::EXP_BIAS;
142
143
if (BIASED_EXPONENT_LIMIT > FPBits::MAX_BIASED_EXPONENT)
143
144
return ;
@@ -179,7 +180,7 @@ class RoundToIntegerTestTemplate
179
180
else
180
181
erangeflag = mpfr::round_to_long (x, mpfr_long_result);
181
182
ASSERT_FALSE (erangeflag);
182
- I mpfr_result = mpfr_long_result;
183
+ OutType mpfr_result = mpfr_long_result;
183
184
test_one_input (func, x, mpfr_result, false );
184
185
}
185
186
}
@@ -201,12 +202,12 @@ class RoundToIntegerTestTemplate
201
202
// This function compares with an equivalent MPFR function which rounds
202
203
// floating point numbers to long values. There is no MPFR function to
203
204
// round to long long or wider integer values. So, we will peform the
204
- // comparisons in this function only if the width of I less than equal to
205
- // that of long.
206
- if (sizeof (I ) > sizeof (long ))
205
+ // comparisons in this function only if the width of OutType less than equal
206
+ // to that of long.
207
+ if (sizeof (OutType ) > sizeof (long ))
207
208
return ;
208
209
209
- constexpr int EXPONENT_LIMIT = sizeof (I ) * 8 - 1 ;
210
+ constexpr int EXPONENT_LIMIT = sizeof (OutType ) * 8 - 1 ;
210
211
constexpr int BIASED_EXPONENT_LIMIT = EXPONENT_LIMIT + FPBits::EXP_BIAS;
211
212
if (BIASED_EXPONENT_LIMIT > FPBits::MAX_BIASED_EXPONENT)
212
213
return ;
@@ -248,22 +249,22 @@ class RoundToIntegerTestTemplate
248
249
if (TestModes) {
249
250
if (x > 0 ) {
250
251
LIBC_NAMESPACE::fputil::set_round (FE_UPWARD);
251
- test_one_input (func, x, I (1 ), false );
252
+ test_one_input (func, x, OutType (1 ), false );
252
253
LIBC_NAMESPACE::fputil::set_round (FE_DOWNWARD);
253
- test_one_input (func, x, I (0 ), false );
254
+ test_one_input (func, x, OutType (0 ), false );
254
255
LIBC_NAMESPACE::fputil::set_round (FE_TOWARDZERO);
255
- test_one_input (func, x, I (0 ), false );
256
+ test_one_input (func, x, OutType (0 ), false );
256
257
LIBC_NAMESPACE::fputil::set_round (FE_TONEAREST);
257
- test_one_input (func, x, I (0 ), false );
258
+ test_one_input (func, x, OutType (0 ), false );
258
259
} else {
259
260
LIBC_NAMESPACE::fputil::set_round (FE_UPWARD);
260
- test_one_input (func, x, I (0 ), false );
261
+ test_one_input (func, x, OutType (0 ), false );
261
262
LIBC_NAMESPACE::fputil::set_round (FE_DOWNWARD);
262
- test_one_input (func, x, I (-1 ), false );
263
+ test_one_input (func, x, OutType (-1 ), false );
263
264
LIBC_NAMESPACE::fputil::set_round (FE_TOWARDZERO);
264
- test_one_input (func, x, I (0 ), false );
265
+ test_one_input (func, x, OutType (0 ), false );
265
266
LIBC_NAMESPACE::fputil::set_round (FE_TONEAREST);
266
- test_one_input (func, x, I (0 ), false );
267
+ test_one_input (func, x, OutType (0 ), false );
267
268
}
268
269
} else {
269
270
test_one_input (func, x, 0L , false );
@@ -275,9 +276,9 @@ class RoundToIntegerTestTemplate
275
276
// This function compares with an equivalent MPFR function which rounds
276
277
// floating point numbers to long values. There is no MPFR function to
277
278
// round to long long or wider integer values. So, we will peform the
278
- // comparisons in this function only if the width of I less than equal to
279
- // that of long.
280
- if (sizeof (I ) > sizeof (long ))
279
+ // comparisons in this function only if the width of OutType less than equal
280
+ // to that of long.
281
+ if (sizeof (OutType ) > sizeof (long ))
281
282
return ;
282
283
283
284
constexpr int COUNT = 1'000'001 ;
@@ -297,7 +298,7 @@ class RoundToIntegerTestTemplate
297
298
long mpfr_long_result;
298
299
bool erangeflag = mpfr::round_to_long (x, to_mpfr_rounding_mode (m),
299
300
mpfr_long_result);
300
- I mpfr_result = mpfr_long_result;
301
+ OutType mpfr_result = mpfr_long_result;
301
302
LIBC_NAMESPACE::fputil::set_round (m);
302
303
if (erangeflag)
303
304
test_one_input (func, x, x > 0 ? INTEGER_MAX : INTEGER_MIN, true );
@@ -307,7 +308,7 @@ class RoundToIntegerTestTemplate
307
308
} else {
308
309
long mpfr_long_result;
309
310
bool erangeflag = mpfr::round_to_long (x, mpfr_long_result);
310
- I mpfr_result = mpfr_long_result;
311
+ OutType mpfr_result = mpfr_long_result;
311
312
if (erangeflag)
312
313
test_one_input (func, x, x > 0 ? INTEGER_MAX : INTEGER_MIN, true );
313
314
else
@@ -317,9 +318,9 @@ class RoundToIntegerTestTemplate
317
318
}
318
319
};
319
320
320
- #define LIST_ROUND_TO_INTEGER_TESTS_HELPER (F, I , func, TestModes ) \
321
+ #define LIST_ROUND_TO_INTEGER_TESTS_HELPER (F, OutType , func, TestModes ) \
321
322
using LlvmLibcRoundToIntegerTest = \
322
- RoundToIntegerTestTemplate<F, I , TestModes>; \
323
+ RoundToIntegerTestTemplate<F, OutType , TestModes>; \
323
324
TEST_F (LlvmLibcRoundToIntegerTest, InfinityAndNaN) { \
324
325
testInfinityAndNaN (&func); \
325
326
} \
@@ -335,10 +336,10 @@ class RoundToIntegerTestTemplate
335
336
} \
336
337
TEST_F (LlvmLibcRoundToIntegerTest, NormalRange) { testNormalRange (&func); }
337
338
338
- #define LIST_ROUND_TO_INTEGER_TESTS (F, I , func ) \
339
- LIST_ROUND_TO_INTEGER_TESTS_HELPER (F, I , func, false )
339
+ #define LIST_ROUND_TO_INTEGER_TESTS (F, OutType , func ) \
340
+ LIST_ROUND_TO_INTEGER_TESTS_HELPER (F, OutType , func, false )
340
341
341
- #define LIST_ROUND_TO_INTEGER_TESTS_WITH_MODES (F, I , func ) \
342
- LIST_ROUND_TO_INTEGER_TESTS_HELPER (F, I , func, true )
342
+ #define LIST_ROUND_TO_INTEGER_TESTS_WITH_MODES (F, OutType , func ) \
343
+ LIST_ROUND_TO_INTEGER_TESTS_HELPER (F, OutType , func, true )
343
344
344
345
#endif // LLVM_LIBC_TEST_SRC_MATH_ROUNDTOINTEGERTEST_H
0 commit comments