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