1 //===-- Unittests for asinf
2 //------------------------------------------------===//
4 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
5 // See https://llvm.org/LICENSE.txt for license information.
6 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
8 //===----------------------------------------------------------------------===//
10 #include "src/__support/FPUtil/FPBits.h"
11 #include "src/errno/libc_errno.h"
12 #include "src/math/asinf.h"
13 #include "test/UnitTest/FPMatcher.h"
14 #include "test/UnitTest/Test.h"
15 #include "utils/MPFRWrapper/MPFRUtils.h"
21 using LlvmLibcAsinfTest
= LIBC_NAMESPACE::testing::FPTest
<float>;
23 namespace mpfr
= LIBC_NAMESPACE::testing::mpfr
;
25 TEST_F(LlvmLibcAsinfTest
, SpecialNumbers
) {
28 EXPECT_FP_EQ_ALL_ROUNDING(aNaN
, LIBC_NAMESPACE::asinf(aNaN
));
31 EXPECT_FP_EQ_ALL_ROUNDING(0.0f
, LIBC_NAMESPACE::asinf(0.0f
));
34 EXPECT_FP_EQ_ALL_ROUNDING(-0.0f
, LIBC_NAMESPACE::asinf(-0.0f
));
37 EXPECT_FP_EQ_ALL_ROUNDING(aNaN
, LIBC_NAMESPACE::asinf(inf
));
38 EXPECT_MATH_ERRNO(EDOM
);
40 EXPECT_FP_EQ_ALL_ROUNDING(aNaN
, LIBC_NAMESPACE::asinf(neg_inf
));
41 EXPECT_MATH_ERRNO(EDOM
);
44 TEST_F(LlvmLibcAsinfTest
, InFloatRange
) {
45 constexpr uint32_t COUNT
= 100'000;
46 constexpr uint32_t STEP
= UINT32_MAX
/ COUNT
;
47 for (uint32_t i
= 0, v
= 0; i
<= COUNT
; ++i
, v
+= STEP
) {
48 float x
= float(FPBits(v
));
49 if (isnan(x
) || isinf(x
))
51 ASSERT_MPFR_MATCH_ALL_ROUNDING(mpfr::Operation::Asin
, x
,
52 LIBC_NAMESPACE::asinf(x
), 0.5);
56 TEST_F(LlvmLibcAsinfTest
, SpecificBitPatterns
) {
58 constexpr uint32_t INPUTS
[N
] = {
59 0x3f000000, // x = 0.5f
60 0x3f3504f3, // x = sqrt(2)/2, FE_DOWNWARD
61 0x3f3504f4, // x = sqrt(2)/2, FE_UPWARD
62 0x3f5db3d7, // x = sqrt(3)/2, FE_DOWNWARD
63 0x3f5db3d8, // x = sqrt(3)/2, FE_UPWARD
64 0x3f800000, // x = 1.0f
65 0x40000000, // x = 2.0f
66 0x3d09bf86, // x = 0x1.137f0cp-5f
67 0x3de5fa1e, // x = 0x1.cbf43cp-4f
68 0x3f083a1a, // x = 0x1.107434p-1f
69 0x3f7741b6, // x = 0x1.ee836cp-1f
72 for (int i
= 0; i
< N
; ++i
) {
73 float x
= float(FPBits(INPUTS
[i
]));
74 EXPECT_MPFR_MATCH_ALL_ROUNDING(mpfr::Operation::Asin
, x
,
75 LIBC_NAMESPACE::asinf(x
), 0.5);
76 EXPECT_MPFR_MATCH_ALL_ROUNDING(mpfr::Operation::Asin
, -x
,
77 LIBC_NAMESPACE::asinf(-x
), 0.5);