1 | //===-- Unittests for atanhf ----------------------------------------------===// |
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 | //===----------------------------------------------------------------------===// |
8 | |
9 | #include "hdr/math_macros.h" |
10 | #include "src/__support/FPUtil/FPBits.h" |
11 | #include "src/errno/libc_errno.h" |
12 | #include "src/math/atanhf.h" |
13 | #include "test/UnitTest/FPMatcher.h" |
14 | #include "test/UnitTest/Test.h" |
15 | |
16 | #include <errno.h> |
17 | #include <stdint.h> |
18 | |
19 | using LlvmLibcAtanhfTest = LIBC_NAMESPACE::testing::FPTest<float>; |
20 | |
21 | TEST_F(LlvmLibcAtanhfTest, SpecialNumbers) { |
22 | |
23 | LIBC_NAMESPACE::libc_errno = 0; |
24 | |
25 | LIBC_NAMESPACE::fputil::clear_except(FE_ALL_EXCEPT); |
26 | EXPECT_FP_EQ_ALL_ROUNDING(aNaN, LIBC_NAMESPACE::atanhf(aNaN)); |
27 | EXPECT_FP_EXCEPTION(0); |
28 | EXPECT_MATH_ERRNO(0); |
29 | |
30 | LIBC_NAMESPACE::fputil::clear_except(FE_ALL_EXCEPT); |
31 | EXPECT_FP_EQ_ALL_ROUNDING(0.0f, LIBC_NAMESPACE::atanhf(0.0f)); |
32 | EXPECT_FP_EXCEPTION(0); |
33 | EXPECT_MATH_ERRNO(0); |
34 | |
35 | LIBC_NAMESPACE::fputil::clear_except(FE_ALL_EXCEPT); |
36 | EXPECT_FP_EQ_ALL_ROUNDING(-0.0f, LIBC_NAMESPACE::atanhf(-0.0f)); |
37 | EXPECT_FP_EXCEPTION(0); |
38 | EXPECT_MATH_ERRNO(0); |
39 | |
40 | EXPECT_FP_EQ_WITH_EXCEPTION(inf, LIBC_NAMESPACE::atanhf(1.0f), FE_DIVBYZERO); |
41 | EXPECT_MATH_ERRNO(ERANGE); |
42 | |
43 | EXPECT_FP_EQ_WITH_EXCEPTION(neg_inf, LIBC_NAMESPACE::atanhf(-1.0f), |
44 | FE_DIVBYZERO); |
45 | EXPECT_MATH_ERRNO(ERANGE); |
46 | |
47 | auto bt = FPBits(1.0f); |
48 | bt.set_uintval(bt.uintval() + 1); |
49 | |
50 | EXPECT_FP_IS_NAN_WITH_EXCEPTION(LIBC_NAMESPACE::atanhf(bt.get_val()), |
51 | FE_INVALID); |
52 | EXPECT_MATH_ERRNO(EDOM); |
53 | |
54 | bt.set_sign(Sign::NEG); |
55 | EXPECT_FP_IS_NAN_WITH_EXCEPTION(LIBC_NAMESPACE::atanhf(bt.get_val()), |
56 | FE_INVALID); |
57 | EXPECT_MATH_ERRNO(EDOM); |
58 | |
59 | EXPECT_FP_IS_NAN_WITH_EXCEPTION(LIBC_NAMESPACE::atanhf(2.0f), FE_INVALID); |
60 | EXPECT_MATH_ERRNO(EDOM); |
61 | |
62 | EXPECT_FP_IS_NAN_WITH_EXCEPTION(LIBC_NAMESPACE::atanhf(-2.0f), FE_INVALID); |
63 | EXPECT_MATH_ERRNO(EDOM); |
64 | |
65 | EXPECT_FP_IS_NAN_WITH_EXCEPTION(LIBC_NAMESPACE::atanhf(inf), FE_INVALID); |
66 | EXPECT_MATH_ERRNO(EDOM); |
67 | |
68 | bt.set_sign(Sign::NEG); |
69 | EXPECT_FP_IS_NAN_WITH_EXCEPTION(LIBC_NAMESPACE::atanhf(neg_inf), FE_INVALID); |
70 | EXPECT_MATH_ERRNO(EDOM); |
71 | } |
72 | |