1#include "str_to_fp_test.h"
2
3namespace LIBC_NAMESPACE {
4
5using LlvmLibcStrToFltTest = LlvmLibcStrToFloatTest<float>;
6
7TEST_F(LlvmLibcStrToFltTest, ClingerFastPathFloat32Simple) {
8 clinger_fast_path_test(inputMantissa: 123, inputExp10: 0, expectedOutputMantissa: 0x760000, expectedOutputExp2: 133);
9 clinger_fast_path_test(inputMantissa: 1234567, inputExp10: 1, expectedOutputMantissa: 0x3c6146, expectedOutputExp2: 150);
10 clinger_fast_path_test(inputMantissa: 12345, inputExp10: -5, expectedOutputMantissa: 0x7cd35b, expectedOutputExp2: 123);
11}
12
13TEST_F(LlvmLibcStrToFltTest, ClingerFastPathFloat32ExtendedExp) {
14 clinger_fast_path_test(inputMantissa: 1, inputExp10: 15, expectedOutputMantissa: 0x635fa9, expectedOutputExp2: 176);
15 clinger_fast_path_test(inputMantissa: 1, inputExp10: 17, expectedOutputMantissa: 0x31a2bc, expectedOutputExp2: 183);
16 clinger_fast_path_fails_test(inputMantissa: 10, inputExp10: 17);
17 clinger_fast_path_fails_test(inputMantissa: 1, inputExp10: 50);
18}
19
20TEST_F(LlvmLibcStrToFltTest, ClingerFastPathFloat32NegativeExp) {
21 clinger_fast_path_test(inputMantissa: 1, inputExp10: -5, expectedOutputMantissa: 0x27c5ac, expectedOutputExp2: 110);
22 clinger_fast_path_test(inputMantissa: 1, inputExp10: -10, expectedOutputMantissa: 0x5be6ff, expectedOutputExp2: 93);
23 clinger_fast_path_fails_test(inputMantissa: 1, inputExp10: -15);
24}
25
26// Check the fallback states for the algorithm:
27TEST_F(LlvmLibcStrToFltTest, EiselLemireFallbackStates) {
28 // This number can't be evaluated by Eisel-Lemire since it's exactly 1024 away
29 // from both of its closest floating point approximations
30 // (12345678901234548736 and 12345678901234550784)
31 ASSERT_FALSE(internal::eisel_lemire<float>({20040229, 0}).has_value());
32}
33
34TEST_F(LlvmLibcStrToFltTest, SimpleDecimalConversion32SpecificFailures) {
35 simple_decimal_conversion_test(
36 numStart: "1.4012984643248170709237295832899161312802619418765e-45", expectedOutputMantissa: 0x1, expectedOutputExp2: 0,
37 ERANGE);
38 simple_decimal_conversion_test(
39 numStart: "7."
40 "006492321624085354618647916449580656401309709382578858785341419448955413"
41 "42930300743319094181060791015625e-46",
42 expectedOutputMantissa: 0x0, expectedOutputExp2: 0, ERANGE);
43}
44
45TEST(LlvmLibcStrToFltTest, SimpleDecimalConversionExtraTypes) {
46 uint32_t float_output_mantissa = 0;
47 uint32_t output_exp2 = 0;
48
49 LIBC_NAMESPACE::libc_errno = 0;
50 auto float_result =
51 internal::simple_decimal_conversion<float>(numStart: "123456789012345678900");
52 float_output_mantissa = float_result.num.mantissa;
53 output_exp2 = float_result.num.exponent;
54 EXPECT_EQ(float_output_mantissa, uint32_t(0xd629d4));
55 EXPECT_EQ(output_exp2, uint32_t(193));
56 EXPECT_EQ(float_result.error, 0);
57}
58
59} // namespace LIBC_NAMESPACE
60

source code of libc/test/src/__support/str_to_float_test.cpp