1 //===-- Unittests for atof ------------------------------------------------===//
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
7 //===----------------------------------------------------------------------===//
9 #include "src/__support/FPUtil/FPBits.h"
10 #include "src/stdlib/atof.h"
12 #include "test/UnitTest/Test.h"
18 // This is just a simple test to make sure that this function works at all. It's
19 // functionally identical to strtod so the bulk of the testing is there.
20 TEST(LlvmLibcAToFTest
, SimpleTest
) {
21 __llvm_libc::fputil::FPBits
<double> expected_fp
=
22 __llvm_libc::fputil::FPBits
<double>(uint64_t(0x405ec00000000000));
25 double result
= __llvm_libc::atof("123");
27 __llvm_libc::fputil::FPBits
<double> actual_fp
=
28 __llvm_libc::fputil::FPBits
<double>(result
);
30 EXPECT_EQ(actual_fp
.bits
, expected_fp
.bits
);
31 EXPECT_EQ(actual_fp
.get_sign(), expected_fp
.get_sign());
32 EXPECT_EQ(actual_fp
.get_exponent(), expected_fp
.get_exponent());
33 EXPECT_EQ(actual_fp
.get_mantissa(), expected_fp
.get_mantissa());
37 TEST(LlvmLibcAToFTest
, FailedParsingTest
) {
38 __llvm_libc::fputil::FPBits
<double> expected_fp
=
39 __llvm_libc::fputil::FPBits
<double>(uint64_t(0));
42 double result
= __llvm_libc::atof("???");
44 __llvm_libc::fputil::FPBits
<double> actual_fp
=
45 __llvm_libc::fputil::FPBits
<double>(result
);
47 EXPECT_EQ(actual_fp
.bits
, expected_fp
.bits
);
48 EXPECT_EQ(actual_fp
.get_sign(), expected_fp
.get_sign());
49 EXPECT_EQ(actual_fp
.get_exponent(), expected_fp
.get_exponent());
50 EXPECT_EQ(actual_fp
.get_mantissa(), expected_fp
.get_mantissa());