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/math/asinf.h"
12 #include "test/UnitTest/FPMatcher.h"
13 #include "test/UnitTest/Test.h"
14 #include "utils/MPFRWrapper/MPFRUtils.h"
20 using FPBits
= __llvm_libc::fputil::FPBits
<float>;
22 namespace mpfr
= __llvm_libc::testing::mpfr
;
24 DECLARE_SPECIAL_CONSTANTS(float)
26 TEST(LlvmLibcAsinfTest
, SpecialNumbers
) {
29 EXPECT_FP_EQ(aNaN
, __llvm_libc::asinf(aNaN
));
32 EXPECT_FP_EQ(0.0f
, __llvm_libc::asinf(0.0f
));
35 EXPECT_FP_EQ(-0.0f
, __llvm_libc::asinf(-0.0f
));
38 EXPECT_FP_EQ(aNaN
, __llvm_libc::asinf(inf
));
39 EXPECT_MATH_ERRNO(EDOM
);
41 EXPECT_FP_EQ(aNaN
, __llvm_libc::asinf(neg_inf
));
42 EXPECT_MATH_ERRNO(EDOM
);
45 TEST(LlvmLibcAsinfTest
, InFloatRange
) {
46 constexpr uint32_t COUNT
= 1000000;
47 constexpr uint32_t STEP
= UINT32_MAX
/ COUNT
;
48 for (uint32_t i
= 0, v
= 0; i
<= COUNT
; ++i
, v
+= STEP
) {
49 float x
= float(FPBits(v
));
50 if (isnan(x
) || isinf(x
))
52 ASSERT_MPFR_MATCH_ALL_ROUNDING(mpfr::Operation::Asin
, x
,
53 __llvm_libc::asinf(x
), 0.5);
57 TEST(LlvmLibcAsinfTest
, SpecificBitPatterns
) {
59 constexpr uint32_t INPUTS
[N
] = {
60 0x3f000000, // x = 0.5f
61 0x3f3504f3, // x = sqrt(2)/2, FE_DOWNWARD
62 0x3f3504f4, // x = sqrt(2)/2, FE_UPWARD
63 0x3f5db3d7, // x = sqrt(3)/2, FE_DOWNWARD
64 0x3f5db3d8, // x = sqrt(3)/2, FE_UPWARD
65 0x3f800000, // x = 1.0f
66 0x40000000, // x = 2.0f
67 0x3d09bf86, // x = 0x1.137f0cp-5f
68 0x3de5fa1e, // x = 0x1.cbf43cp-4f
69 0x3f083a1a, // x = 0x1.107434p-1f
70 0x3f7741b6, // x = 0x1.ee836cp-1f
73 for (int i
= 0; i
< N
; ++i
) {
74 float x
= float(FPBits(INPUTS
[i
]));
75 EXPECT_MPFR_MATCH_ALL_ROUNDING(mpfr::Operation::Asin
, x
,
76 __llvm_libc::asinf(x
), 0.5);
77 EXPECT_MPFR_MATCH_ALL_ROUNDING(mpfr::Operation::Asin
, -x
,
78 __llvm_libc::asinf(-x
), 0.5);