1 //===-- Unittests for asinhf ----------------------------------------------===//
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/errno/libc_errno.h"
11 #include "src/math/asinhf.h"
12 #include "test/UnitTest/FPMatcher.h"
13 #include "test/UnitTest/Test.h"
14 #include "utils/MPFRWrapper/MPFRUtils.h"
20 using LlvmLibcAsinhfTest
= LIBC_NAMESPACE::testing::FPTest
<float>;
22 namespace mpfr
= LIBC_NAMESPACE::testing::mpfr
;
24 TEST_F(LlvmLibcAsinhfTest
, SpecialNumbers
) {
27 EXPECT_FP_EQ_ALL_ROUNDING(aNaN
, LIBC_NAMESPACE::asinhf(aNaN
));
30 EXPECT_FP_EQ_ALL_ROUNDING(0.0f
, LIBC_NAMESPACE::asinhf(0.0f
));
33 EXPECT_FP_EQ_ALL_ROUNDING(-0.0f
, LIBC_NAMESPACE::asinhf(-0.0f
));
36 EXPECT_FP_EQ_ALL_ROUNDING(inf
, LIBC_NAMESPACE::asinhf(inf
));
39 EXPECT_FP_EQ_ALL_ROUNDING(neg_inf
, LIBC_NAMESPACE::asinhf(neg_inf
));
43 TEST_F(LlvmLibcAsinhfTest
, InFloatRange
) {
44 constexpr uint32_t COUNT
= 1'001;
45 constexpr uint32_t STEP
= UINT32_MAX
/ COUNT
;
46 for (uint32_t i
= 0, v
= 0; i
<= COUNT
; ++i
, v
+= STEP
) {
47 float x
= float(FPBits(v
));
48 if (isnan(x
) || isinf(x
))
50 ASSERT_MPFR_MATCH_ALL_ROUNDING(mpfr::Operation::Asinh
, x
,
51 LIBC_NAMESPACE::asinhf(x
), 0.5);
52 ASSERT_MPFR_MATCH_ALL_ROUNDING(mpfr::Operation::Asinh
, -x
,
53 LIBC_NAMESPACE::asinhf(-x
), 0.5);
57 TEST_F(LlvmLibcAsinhfTest
, SpecificBitPatterns
) {
59 constexpr uint32_t INPUTS
[N
] = {
60 0x45abaf26, // |x| = 0x1.575e4cp12f
61 0x49d29048, // |x| = 0x1.a5209p20f
62 0x4bdd65a5, // |x| = 0x1.bacb4ap24f
63 0x4c803f2c, // |x| = 0x1.007e58p26f
64 0x4f8ffb03, // |x| = 0x1.1ff606p32f
65 0x5c569e88, // |x| = 0x1.ad3d1p57f
66 0x5e68984e, // |x| = 0x1.d1309cp61f
67 0x655890d3, // |x| = 0x1.b121a6p75f
68 0x65de7ca6, // |x| = 0x1.bcf94cp76f
69 0x6eb1a8ec, // |x| = 0x1.6351d8p94f
70 0x7997f30a, // |x| = 0x1.2fe614p116f
73 for (int i
= 0; i
< N
; ++i
) {
74 float x
= float(FPBits(INPUTS
[i
]));
75 EXPECT_MPFR_MATCH_ALL_ROUNDING(mpfr::Operation::Asinh
, x
,
76 LIBC_NAMESPACE::asinhf(x
), 0.5);
77 EXPECT_MPFR_MATCH_ALL_ROUNDING(mpfr::Operation::Asinh
, -x
,
78 LIBC_NAMESPACE::asinhf(-x
), 0.5);