[OptTable] Fix typo VALUE => VALUES (NFCI) (#121523)
[llvm-project.git] / libc / test / src / __support / str_to_fp_test.h
blobdb4e62a5cd0d11d2458d96dbb0b69944fdaa6846
1 //===-- Unittests for str_to_float ----------------------------------------===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
9 #include "src/__support/FPUtil/FPBits.h"
10 #include "src/__support/macros/config.h"
11 #include "src/__support/str_to_float.h"
12 #include "src/__support/uint128.h"
13 #include "src/errno/libc_errno.h"
15 #include "test/UnitTest/Test.h"
17 namespace LIBC_NAMESPACE_DECL {
19 template <typename T> struct LlvmLibcStrToFloatTest : public testing::Test {
20 using StorageType = typename fputil::FPBits<T>::StorageType;
22 void clinger_fast_path_test(const StorageType inputMantissa,
23 const int32_t inputExp10,
24 const StorageType expectedOutputMantissa,
25 const uint32_t expectedOutputExp2) {
26 StorageType actual_output_mantissa = 0;
27 uint32_t actual_output_exp2 = 0;
29 auto result = internal::clinger_fast_path<T>({inputMantissa, inputExp10});
31 ASSERT_TRUE(result.has_value());
33 actual_output_mantissa = result->mantissa;
34 actual_output_exp2 = result->exponent;
36 EXPECT_EQ(actual_output_mantissa, expectedOutputMantissa);
37 EXPECT_EQ(actual_output_exp2, expectedOutputExp2);
40 void clinger_fast_path_fails_test(const StorageType inputMantissa,
41 const int32_t inputExp10) {
42 ASSERT_FALSE(internal::clinger_fast_path<T>({inputMantissa, inputExp10})
43 .has_value());
46 void eisel_lemire_test(const StorageType inputMantissa,
47 const int32_t inputExp10,
48 const StorageType expectedOutputMantissa,
49 const uint32_t expectedOutputExp2) {
50 StorageType actual_output_mantissa = 0;
51 uint32_t actual_output_exp2 = 0;
53 auto result = internal::eisel_lemire<T>({inputMantissa, inputExp10});
55 ASSERT_TRUE(result.has_value());
57 actual_output_mantissa = result->mantissa;
58 actual_output_exp2 = result->exponent;
60 EXPECT_EQ(actual_output_mantissa, expectedOutputMantissa);
61 EXPECT_EQ(actual_output_exp2, expectedOutputExp2);
64 void simple_decimal_conversion_test(const char *__restrict numStart,
65 const StorageType expectedOutputMantissa,
66 const uint32_t expectedOutputExp2,
67 const int expectedErrno = 0) {
68 StorageType actual_output_mantissa = 0;
69 uint32_t actual_output_exp2 = 0;
70 LIBC_NAMESPACE::libc_errno = 0;
72 auto result = internal::simple_decimal_conversion<T>(numStart);
74 actual_output_mantissa = result.num.mantissa;
75 actual_output_exp2 = result.num.exponent;
77 EXPECT_EQ(actual_output_mantissa, expectedOutputMantissa);
78 EXPECT_EQ(actual_output_exp2, expectedOutputExp2);
79 EXPECT_EQ(result.error, expectedErrno);
83 } // namespace LIBC_NAMESPACE_DECL