Skip to content

Commit 7299c7f

Browse files
[libc] Fix CFP long double and add tests (#102660)
The previous patch removing the fenv requirement for str to float had an error that got missed due to a lack of tests. This patch fixes the issue and adds tests, as well as updating the existing tests.
1 parent bbefd57 commit 7299c7f

File tree

4 files changed

+32
-17
lines changed

4 files changed

+32
-17
lines changed

libc/src/__support/str_to_float.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -526,8 +526,8 @@ clinger_fast_path(ExpandedFloat<T> init_num,
526526
T float_mantissa;
527527
if constexpr (cpp::is_same_v<StorageType, UInt<128>>) {
528528
float_mantissa =
529-
(static_cast<T>(uint64_t(mantissa)) * static_cast<T>(0x1.0p64)) +
530-
static_cast<T>(uint64_t(mantissa >> 64));
529+
(static_cast<T>(uint64_t(mantissa >> 64)) * static_cast<T>(0x1.0p64)) +
530+
static_cast<T>(uint64_t(mantissa));
531531
} else {
532532
float_mantissa = static_cast<T>(mantissa);
533533
}
@@ -591,7 +591,7 @@ clinger_fast_path(ExpandedFloat<T> init_num,
591591
}
592592

593593
ExpandedFloat<T> output;
594-
output.mantissa = result.get_mantissa();
594+
output.mantissa = result.get_explicit_mantissa();
595595
output.exponent = result.get_biased_exponent();
596596
return output;
597597
}

libc/test/src/__support/str_to_double_test.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,21 +5,21 @@ namespace LIBC_NAMESPACE_DECL {
55
using LlvmLibcStrToDblTest = LlvmLibcStrToFloatTest<double>;
66

77
TEST_F(LlvmLibcStrToDblTest, ClingerFastPathFloat64Simple) {
8-
clinger_fast_path_test(123, 0, 0xEC00000000000, 1029);
9-
clinger_fast_path_test(1234567890123456, 1, 0x5ee2a2eb5a5c0, 1076);
10-
clinger_fast_path_test(1234567890, -10, 0xf9add3739635f, 1019);
8+
clinger_fast_path_test(123, 0, 0x1EC00000000000, 1029);
9+
clinger_fast_path_test(1234567890123456, 1, 0x15ee2a2eb5a5c0, 1076);
10+
clinger_fast_path_test(1234567890, -10, 0x1f9add3739635f, 1019);
1111
}
1212

1313
TEST_F(LlvmLibcStrToDblTest, ClingerFastPathFloat64ExtendedExp) {
14-
clinger_fast_path_test(1, 30, 0x93e5939a08cea, 1122);
15-
clinger_fast_path_test(1, 37, 0xe17b84357691b, 1145);
14+
clinger_fast_path_test(1, 30, 0x193e5939a08cea, 1122);
15+
clinger_fast_path_test(1, 37, 0x1e17b84357691b, 1145);
1616
clinger_fast_path_fails_test(10, 37);
1717
clinger_fast_path_fails_test(1, 100);
1818
}
1919

2020
TEST_F(LlvmLibcStrToDblTest, ClingerFastPathFloat64NegativeExp) {
21-
clinger_fast_path_test(1, -10, 0xb7cdfd9d7bdbb, 989);
22-
clinger_fast_path_test(1, -20, 0x79ca10c924223, 956);
21+
clinger_fast_path_test(1, -10, 0x1b7cdfd9d7bdbb, 989);
22+
clinger_fast_path_test(1, -20, 0x179ca10c924223, 956);
2323
clinger_fast_path_fails_test(1, -25);
2424
}
2525

libc/test/src/__support/str_to_float_test.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,21 +6,21 @@ namespace LIBC_NAMESPACE_DECL {
66
using LlvmLibcStrToFltTest = LlvmLibcStrToFloatTest<float>;
77

88
TEST_F(LlvmLibcStrToFltTest, ClingerFastPathFloat32Simple) {
9-
clinger_fast_path_test(123, 0, 0x760000, 133);
10-
clinger_fast_path_test(1234567, 1, 0x3c6146, 150);
11-
clinger_fast_path_test(12345, -5, 0x7cd35b, 123);
9+
clinger_fast_path_test(123, 0, 0xf60000, 133);
10+
clinger_fast_path_test(1234567, 1, 0xbc6146, 150);
11+
clinger_fast_path_test(12345, -5, 0xfcd35b, 123);
1212
}
1313

1414
TEST_F(LlvmLibcStrToFltTest, ClingerFastPathFloat32ExtendedExp) {
15-
clinger_fast_path_test(1, 15, 0x635fa9, 176);
16-
clinger_fast_path_test(1, 17, 0x31a2bc, 183);
15+
clinger_fast_path_test(1, 15, 0xe35fa9, 176);
16+
clinger_fast_path_test(1, 17, 0xb1a2bc, 183);
1717
clinger_fast_path_fails_test(10, 17);
1818
clinger_fast_path_fails_test(1, 50);
1919
}
2020

2121
TEST_F(LlvmLibcStrToFltTest, ClingerFastPathFloat32NegativeExp) {
22-
clinger_fast_path_test(1, -5, 0x27c5ac, 110);
23-
clinger_fast_path_test(1, -10, 0x5be6ff, 93);
22+
clinger_fast_path_test(1, -5, 0xa7c5ac, 110);
23+
clinger_fast_path_test(1, -10, 0xdbe6ff, 93);
2424
clinger_fast_path_fails_test(1, -15);
2525
}
2626

libc/test/src/__support/str_to_long_double_test.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,12 @@ TEST_F(LlvmLibcStrToLongDblTest, EiselLemireFloat80Fallback) {
5555
ASSERT_FALSE(internal::eisel_lemire<long double>({1, -1000}).has_value());
5656
}
5757

58+
TEST_F(LlvmLibcStrToLongDblTest, ClingerFastPathFloat80Simple) {
59+
clinger_fast_path_test(123, 0, 0xf600000000000000, 16389);
60+
clinger_fast_path_test(1234567, 1, 0xbc61460000000000, 16406);
61+
clinger_fast_path_test(12345, -5, 0xfcd35a858793dd98, 16379);
62+
}
63+
5864
#elif defined(LIBC_TYPES_LONG_DOUBLE_IS_FLOAT128)
5965

6066
TEST_F(LlvmLibcStrToLongDblTest, EiselLemireFloat128Simple) {
@@ -78,6 +84,15 @@ TEST_F(LlvmLibcStrToLongDblTest, EiselLemireFloat128Fallback) {
7884
.has_value());
7985
}
8086

87+
TEST_F(LlvmLibcStrToLongDblTest, ClingerFastPathFloat128Simple) {
88+
clinger_fast_path_test(123, 0, 0x1ec00'00000000'00000000'00000000_u128,
89+
16389);
90+
clinger_fast_path_test(1234567, 1, 0x178c2'8c000000'00000000'00000000_u128,
91+
16406);
92+
clinger_fast_path_test(12345, -5, 0x1f9a6'b50b0f27'bb2fec56'd5cfaace_u128,
93+
16379);
94+
}
95+
8196
#else
8297
#error "Unknown long double type"
8398
#endif

0 commit comments

Comments
 (0)