10
10
#define LLVM_LIBC_TEST_SRC_MATH_SMOKE_CANONICALIZETEST_H
11
11
12
12
#include " src/__support/FPUtil/FPBits.h"
13
- #include " src/__support/integer_literals.h"
14
13
#include " test/UnitTest/FPMatcher.h"
15
14
#include " test/UnitTest/Test.h"
16
15
23
22
24
23
#define TEST_REGULAR (x, y, expected ) TEST_SPECIAL(x, y, expected, 0 )
25
24
26
- using LIBC_NAMESPACE::operator " " _u128;
27
-
28
25
template <typename T>
29
26
class CanonicalizeTest : public LIBC_NAMESPACE ::testing::Test {
30
27
@@ -58,54 +55,57 @@ class CanonicalizeTest : public LIBC_NAMESPACE::testing::Test {
58
55
T cx;
59
56
// Exponent | Significand | Meaning
60
57
// | Bits 63-62 | Bits 61-0 |
61
- // All Ones | 00 | Zero | Pseudo Infinity, Value = SNaN
62
- FPBits test1 (0x00000000'00007FFF'00000000' 00000000_u128);
58
+ // All Ones | 00 | Zero | Pseudo Infinity, Value = Infinty
59
+
60
+ FPBits test1 ((UInt128 (0x7FFF ) << 64 ) + UInt128 (0x0000000000000000 ));
63
61
const T test1_val = test1.get_val ();
64
- TEST_SPECIAL (cx, test1_val, 1 , FE_INVALID );
65
- EXPECT_FP_EQ (cx, aNaN );
62
+ TEST_SPECIAL (cx, test1_val, 0 , 0 );
63
+ EXPECT_FP_EQ (cx, inf );
66
64
67
65
// Exponent | Significand | Meaning
68
66
// | Bits 63-62 | Bits 61-0 |
69
67
// All Ones | 00 | Non-Zero | Pseudo NaN, Value = SNaN
70
- FPBits test2_1 (0x000000000'00007FFF'00000000' 00000001_u128);
68
+
69
+ FPBits test2_1 ((UInt128 (0x7FFF ) << 64 ) + UInt128 (0x0000000000000001 ));
71
70
const T test2_1_val = test2_1.get_val ();
72
71
TEST_SPECIAL (cx, test2_1_val, 1 , FE_INVALID);
73
72
EXPECT_FP_EQ (cx, aNaN);
74
73
75
- FPBits test2_2 (0x000000000'00007FFF'00000042 ' 70000001_u128 );
74
+ FPBits test2_2 (( UInt128 ( 0x7FFF ) << 64 ) + UInt128 ( 0x0000004270000001 ) );
76
75
const T test2_2_val = test2_2.get_val ();
77
76
TEST_SPECIAL (cx, test2_2_val, 1 , FE_INVALID);
78
77
EXPECT_FP_EQ (cx, aNaN);
79
78
80
- FPBits test2_3 (0x000000000'00007FFF'00000000 ' 08261001_u128 );
79
+ FPBits test2_3 (( UInt128 ( 0x7FFF ) << 64 ) + UInt128 ( 0x0000000008261001 ) );
81
80
const T test2_3_val = test2_3.get_val ();
82
81
TEST_SPECIAL (cx, test2_3_val, 1 , FE_INVALID);
83
82
EXPECT_FP_EQ (cx, aNaN);
84
83
85
- FPBits test2_4 (0x000000000'00007FFF'00007800 ' 08261001_u128 );
84
+ FPBits test2_4 (( UInt128 ( 0x7FFF ) << 64 ) + UInt128 ( 0x0000780008261001 ) );
86
85
const T test2_4_val = test2_4.get_val ();
87
86
TEST_SPECIAL (cx, test2_4_val, 1 , FE_INVALID);
88
87
EXPECT_FP_EQ (cx, aNaN);
89
88
90
89
// Exponent | Significand | Meaning
91
90
// | Bits 63-62 | Bits 61-0 |
92
91
// All Ones | 01 | Anything | Pseudo NaN, Value = SNaN
93
- FPBits test3_1 (0x00000000'00007FFF'40000000' 00000000_u128);
92
+
93
+ FPBits test3_1 ((UInt128 (0x7FFF ) << 64 ) + UInt128 (0x4000000000000000 ));
94
94
const T test3_1_val = test3_1.get_val ();
95
95
TEST_SPECIAL (cx, test3_1_val, 1 , FE_INVALID);
96
96
EXPECT_FP_EQ (cx, aNaN);
97
97
98
- FPBits test3_2 (0x00000000'00007FFF'40000042 ' 70000001_u128 );
98
+ FPBits test3_2 (( UInt128 ( 0x7FFF ) << 64 ) + UInt128 ( 0x4000004270000001 ) );
99
99
const T test3_2_val = test3_2.get_val ();
100
100
TEST_SPECIAL (cx, test3_2_val, 1 , FE_INVALID);
101
101
EXPECT_FP_EQ (cx, aNaN);
102
102
103
- FPBits test3_3 (0x00000000'00007FFF'40000000 ' 08261001_u128 );
103
+ FPBits test3_3 (( UInt128 ( 0x7FFF ) << 64 ) + UInt128 ( 0x4000000008261001 ) );
104
104
const T test3_3_val = test3_3.get_val ();
105
105
TEST_SPECIAL (cx, test3_3_val, 1 , FE_INVALID);
106
106
EXPECT_FP_EQ (cx, aNaN);
107
107
108
- FPBits test3_4 (0x00000000'00007FFF'40007800 ' 08261001_u128 );
108
+ FPBits test3_4 (( UInt128 ( 0x7FFF ) << 64 ) + UInt128 ( 0x4007800008261001 ) );
109
109
const T test3_4_val = test3_4.get_val ();
110
110
TEST_SPECIAL (cx, test3_4_val, 1 , FE_INVALID);
111
111
EXPECT_FP_EQ (cx, aNaN);
@@ -114,56 +114,65 @@ class CanonicalizeTest : public LIBC_NAMESPACE::testing::Test {
114
114
// | Bit 63 | Bits 62-0 |
115
115
// All zeroes | One | Anything | Pseudo Denormal, Value =
116
116
// | | | (−1)**s × m × 2**−16382
117
- FPBits test4_1 (0x00000000'00000000'80000000' 00000000_u128);
117
+
118
+ FPBits test4_1 ((UInt128 (0x0000 ) << 64 ) + UInt128 (0x8000000000000000 ));
118
119
const T test4_1_val = test4_1.get_val ();
119
120
TEST_SPECIAL (cx, test4_1_val, 0 , 0 );
120
121
EXPECT_FP_EQ (
121
122
cx, FPBits::make_value (test4_1.get_explicit_mantissa (), 0 ).get_val ());
122
123
123
- FPBits test4_2 (0x00000000'00000000'80000042 ' 70000001_u128 );
124
+ FPBits test4_2 (( UInt128 ( 0x0000 ) << 64 ) + UInt128 ( 0x8000004270000001 ) );
124
125
const T test4_2_val = test4_2.get_val ();
125
126
TEST_SPECIAL (cx, test4_2_val, 0 , 0 );
126
127
EXPECT_FP_EQ (
127
128
cx, FPBits::make_value (test4_2.get_explicit_mantissa (), 0 ).get_val ());
128
- FPBits test4_3 (0x00000000'00000000'80000000' 08261001_u128);
129
+
130
+ FPBits test4_3 ((UInt128 (0x0000 ) << 64 ) + UInt128 (0x8000000008261001 ));
129
131
const T test4_3_val = test4_3.get_val ();
130
132
TEST_SPECIAL (cx, test4_3_val, 0 , 0 );
131
133
EXPECT_FP_EQ (
132
134
cx, FPBits::make_value (test4_3.get_explicit_mantissa (), 0 ).get_val ());
133
135
134
136
// Exponent | Significand | Meaning
135
137
// | Bit 63 | Bits 62-0 |
136
- // All Other | Zero | Anything | Unnormal, Value = SNaN
137
- // Values | | |
138
- FPBits test5_1 (0x00000000'00000040'00000000' 00000001_u128);
138
+ // All Other | Zero | Anything | Unnormal, Value =
139
+ // Values | | | (−1)**s × m × 2**−16382
140
+
141
+ FPBits test5_1 (UInt128 (0x0000000000000001 ));
139
142
const T test5_1_val = test5_1.get_val ();
140
- TEST_SPECIAL (cx, test5_1_val, 1 , FE_INVALID);
141
- EXPECT_FP_EQ (cx, aNaN);
143
+ TEST_SPECIAL (cx, test5_1_val, 0 , 0 );
144
+ EXPECT_FP_EQ (
145
+ cx, FPBits::make_value (test5_1.get_explicit_mantissa (), 0 ).get_val ());
142
146
143
- FPBits test5_2 (0x00000000'00000230'00000042 ' 70000001_u128 );
147
+ FPBits test5_2 (UInt128 ( 0x0000004270000001 ) );
144
148
const T test5_2_val = test5_2.get_val ();
145
- TEST_SPECIAL (cx, test5_2_val, 1 , FE_INVALID);
146
- EXPECT_FP_EQ (cx, aNaN);
149
+ TEST_SPECIAL (cx, test5_2_val, 0 , 0 );
150
+ EXPECT_FP_EQ (
151
+ cx, FPBits::make_value (test5_2.get_explicit_mantissa (), 0 ).get_val ());
147
152
148
- FPBits test5_3 (0x00000000'00000560'00000000 ' 08261001_u128 );
153
+ FPBits test5_3 (UInt128 ( 0x0000000008261001 ) );
149
154
const T test5_3_val = test5_3.get_val ();
150
- TEST_SPECIAL (cx, test5_3_val, 1 , FE_INVALID);
151
- EXPECT_FP_EQ (cx, aNaN);
155
+ TEST_SPECIAL (cx, test5_3_val, 0 , 0 );
156
+ EXPECT_FP_EQ (
157
+ cx, FPBits::make_value (test5_3.get_explicit_mantissa (), 0 ).get_val ());
152
158
153
- FPBits test5_4 (0x00000000'00000780'00000028 ' 16000000_u128 );
159
+ FPBits test5_4 (UInt128 ( 0x0000002816000000 ) );
154
160
const T test5_4_val = test5_4.get_val ();
155
- TEST_SPECIAL (cx, test5_4_val, 1 , FE_INVALID);
156
- EXPECT_FP_EQ (cx, aNaN);
161
+ TEST_SPECIAL (cx, test5_4_val, 0 , 0 );
162
+ EXPECT_FP_EQ (
163
+ cx, FPBits::make_value (test5_4.get_explicit_mantissa (), 0 ).get_val ());
157
164
158
- FPBits test5_5 (0x00000000'00000900'00000042 ' 70000001_u128 );
165
+ FPBits test5_5 (UInt128 ( 0x0000004270000001 ) );
159
166
const T test5_5_val = test5_5.get_val ();
160
- TEST_SPECIAL (cx, test5_5_val, 1 , FE_INVALID);
161
- EXPECT_FP_EQ (cx, aNaN);
167
+ TEST_SPECIAL (cx, test5_5_val, 0 , 0 );
168
+ EXPECT_FP_EQ (
169
+ cx, FPBits::make_value (test5_5.get_explicit_mantissa (), 0 ).get_val ());
162
170
163
- FPBits test5_6 (0x00000000'00000AB0'00000000 ' 08261001_u128 );
171
+ FPBits test5_6 (UInt128 ( 0x0000000008261001 ) );
164
172
const T test5_6_val = test5_6.get_val ();
165
- TEST_SPECIAL (cx, test5_6_val, 1 , FE_INVALID);
166
- EXPECT_FP_EQ (cx, aNaN);
173
+ TEST_SPECIAL (cx, test5_6_val, 0 , 0 );
174
+ EXPECT_FP_EQ (
175
+ cx, FPBits::make_value (test5_6.get_explicit_mantissa (), 0 ).get_val ());
167
176
}
168
177
}
169
178
0 commit comments