22
22
static constexpr int ROUNDING_MODES[4 ] = {FE_UPWARD, FE_DOWNWARD, FE_TOWARDZERO,
23
23
FE_TONEAREST};
24
24
25
- template <typename F , typename I , bool TestModes = false >
25
+ template <typename FloatType , typename IntType , bool TestModes = false >
26
26
class RoundToIntegerTestTemplate
27
27
: public LIBC_NAMESPACE::testing::FEnvSafeTest {
28
28
public:
29
- typedef I (*RoundToIntegerFunc)(F );
29
+ typedef IntType (*RoundToIntegerFunc)(FloatType );
30
30
31
31
private:
32
- DECLARE_SPECIAL_CONSTANTS (F )
32
+ DECLARE_SPECIAL_CONSTANTS (FloatType )
33
33
34
34
static constexpr StorageType MAX_SUBNORMAL =
35
35
FPBits::max_subnormal ().uintval();
36
36
static constexpr StorageType MIN_SUBNORMAL =
37
37
FPBits::min_subnormal ().uintval();
38
38
39
- static constexpr I INTEGER_MIN = I(1 ) << (sizeof (I) * 8 - 1 );
40
- static constexpr I INTEGER_MAX = -(INTEGER_MIN + 1 );
39
+ static constexpr IntType INTEGER_MIN = IntType(1 )
40
+ << (sizeof (IntType) * 8 - 1 );
41
+ static constexpr IntType INTEGER_MAX = -(INTEGER_MIN + 1 );
41
42
42
- void test_one_input (RoundToIntegerFunc func, F input, I expected ,
43
- bool expectError) {
43
+ void test_one_input (RoundToIntegerFunc func, FloatType input,
44
+ IntType expected, bool expectError) {
44
45
libc_errno = 0 ;
45
46
LIBC_NAMESPACE::fputil::clear_except (FE_ALL_EXCEPT);
46
47
@@ -92,14 +93,14 @@ class RoundToIntegerTestTemplate
92
93
}
93
94
94
95
void do_round_numbers_test (RoundToIntegerFunc func) {
95
- test_one_input (func, zero, I (0 ), false );
96
- test_one_input (func, neg_zero, I (0 ), false );
97
- test_one_input (func, F (1.0 ), I (1 ), false );
98
- test_one_input (func, F (-1.0 ), I (-1 ), false );
99
- test_one_input (func, F (10.0 ), I (10 ), false );
100
- test_one_input (func, F (-10.0 ), I (-10 ), false );
101
- test_one_input (func, F (1232.0 ), I (1232 ), false );
102
- test_one_input (func, F (-1232.0 ), I (-1232 ), false );
96
+ test_one_input (func, zero, IntType (0 ), false );
97
+ test_one_input (func, neg_zero, IntType (0 ), false );
98
+ test_one_input (func, FloatType (1.0 ), IntType (1 ), false );
99
+ test_one_input (func, FloatType (-1.0 ), IntType (-1 ), false );
100
+ test_one_input (func, FloatType (10.0 ), IntType (10 ), false );
101
+ test_one_input (func, FloatType (-10.0 ), IntType (-10 ), false );
102
+ test_one_input (func, FloatType (1232.0 ), IntType (1232 ), false );
103
+ test_one_input (func, FloatType (-1232.0 ), IntType (-1232 ), false );
103
104
}
104
105
105
106
void testRoundNumbers (RoundToIntegerFunc func) {
@@ -120,29 +121,29 @@ class RoundToIntegerTestTemplate
120
121
static_cast <StorageType>((MAX_SUBNORMAL - MIN_SUBNORMAL) / COUNT),
121
122
StorageType (1 ));
122
123
for (StorageType i = MIN_SUBNORMAL; i <= MAX_SUBNORMAL; i += STEP) {
123
- F x = FPBits (i).get_val ();
124
- if (x == F (0.0 ))
124
+ FloatType x = FPBits (i).get_val ();
125
+ if (x == FloatType (0.0 ))
125
126
continue ;
126
127
// All subnormal numbers should round to zero.
127
128
if (TestModes) {
128
129
if (x > zero) {
129
130
LIBC_NAMESPACE::fputil::set_round (FE_UPWARD);
130
- test_one_input (func, x, I (1 ), false );
131
+ test_one_input (func, x, IntType (1 ), false );
131
132
LIBC_NAMESPACE::fputil::set_round (FE_DOWNWARD);
132
- test_one_input (func, x, I (0 ), false );
133
+ test_one_input (func, x, IntType (0 ), false );
133
134
LIBC_NAMESPACE::fputil::set_round (FE_TOWARDZERO);
134
- test_one_input (func, x, I (0 ), false );
135
+ test_one_input (func, x, IntType (0 ), false );
135
136
LIBC_NAMESPACE::fputil::set_round (FE_TONEAREST);
136
- test_one_input (func, x, I (0 ), false );
137
+ test_one_input (func, x, IntType (0 ), false );
137
138
} else {
138
139
LIBC_NAMESPACE::fputil::set_round (FE_UPWARD);
139
- test_one_input (func, x, I (0 ), false );
140
+ test_one_input (func, x, IntType (0 ), false );
140
141
LIBC_NAMESPACE::fputil::set_round (FE_DOWNWARD);
141
- test_one_input (func, x, I (-1 ), false );
142
+ test_one_input (func, x, IntType (-1 ), false );
142
143
LIBC_NAMESPACE::fputil::set_round (FE_TOWARDZERO);
143
- test_one_input (func, x, I (0 ), false );
144
+ test_one_input (func, x, IntType (0 ), false );
144
145
LIBC_NAMESPACE::fputil::set_round (FE_TONEAREST);
145
- test_one_input (func, x, I (0 ), false );
146
+ test_one_input (func, x, IntType (0 ), false );
146
147
}
147
148
} else {
148
149
test_one_input (func, x, 0L , false );
@@ -151,9 +152,10 @@ class RoundToIntegerTestTemplate
151
152
}
152
153
};
153
154
154
- #define LIST_ROUND_TO_INTEGER_TESTS_HELPER (F, I, func, TestModes ) \
155
+ #define LIST_ROUND_TO_INTEGER_TESTS_HELPER (FloatType, IntType, func, \
156
+ TestModes) \
155
157
using LlvmLibcRoundToIntegerTest = \
156
- RoundToIntegerTestTemplate<F, I , TestModes>; \
158
+ RoundToIntegerTestTemplate<FloatType, IntType , TestModes>; \
157
159
TEST_F (LlvmLibcRoundToIntegerTest, InfinityAndNaN) { \
158
160
testInfinityAndNaN (&func); \
159
161
} \
@@ -164,16 +166,16 @@ class RoundToIntegerTestTemplate
164
166
testSubnormalRange (&func); \
165
167
}
166
168
167
- #define LIST_ROUND_TO_INTEGER_TESTS (F, I , func ) \
168
- LIST_ROUND_TO_INTEGER_TESTS_HELPER (F, I , func, false )
169
+ #define LIST_ROUND_TO_INTEGER_TESTS (FloatType, IntType , func ) \
170
+ LIST_ROUND_TO_INTEGER_TESTS_HELPER (FloatType, IntType , func, false )
169
171
170
172
// The GPU target does not support different rounding modes.
171
173
#ifdef LIBC_TARGET_ARCH_IS_GPU
172
- #define LIST_ROUND_TO_INTEGER_TESTS_WITH_MODES (F, I , func ) \
173
- LIST_ROUND_TO_INTEGER_TESTS_HELPER (F, I , func, false )
174
+ #define LIST_ROUND_TO_INTEGER_TESTS_WITH_MODES (FloatType, IntType , func ) \
175
+ LIST_ROUND_TO_INTEGER_TESTS_HELPER (FloatType, IntType , func, false )
174
176
#else
175
- #define LIST_ROUND_TO_INTEGER_TESTS_WITH_MODES (F, I , func ) \
176
- LIST_ROUND_TO_INTEGER_TESTS_HELPER (F, I , func, true )
177
+ #define LIST_ROUND_TO_INTEGER_TESTS_WITH_MODES (FloatType, IntType , func ) \
178
+ LIST_ROUND_TO_INTEGER_TESTS_HELPER (FloatType, IntType , func, true )
177
179
#endif
178
180
179
181
#endif // LLVM_LIBC_TEST_SRC_MATH_SMOKE_ROUNDTOINTEGERTEST_H
0 commit comments