Revert "[lldb][test] Remove compiler version check and use regex" (#124101)
[llvm-project.git] / libc / test / src / math / asinf_test.cpp
blob5197810d8bd5834c17724e29be7e7e3f2bf12084
1 //===-- Unittests for asinf
2 //------------------------------------------------===//
3 //
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
7 //
8 //===----------------------------------------------------------------------===//
10 #include "hdr/math_macros.h"
11 #include "src/__support/FPUtil/FPBits.h"
12 #include "src/errno/libc_errno.h"
13 #include "src/math/asinf.h"
14 #include "test/UnitTest/FPMatcher.h"
15 #include "test/UnitTest/Test.h"
16 #include "utils/MPFRWrapper/MPFRUtils.h"
18 #include <stdint.h>
20 using LlvmLibcAsinfTest = LIBC_NAMESPACE::testing::FPTest<float>;
22 namespace mpfr = LIBC_NAMESPACE::testing::mpfr;
24 TEST_F(LlvmLibcAsinfTest, SpecialNumbers) {
25 LIBC_NAMESPACE::libc_errno = 0;
27 EXPECT_FP_EQ_ALL_ROUNDING(aNaN, LIBC_NAMESPACE::asinf(aNaN));
28 EXPECT_MATH_ERRNO(0);
30 EXPECT_FP_EQ_ALL_ROUNDING(0.0f, LIBC_NAMESPACE::asinf(0.0f));
31 EXPECT_MATH_ERRNO(0);
33 EXPECT_FP_EQ_ALL_ROUNDING(-0.0f, LIBC_NAMESPACE::asinf(-0.0f));
34 EXPECT_MATH_ERRNO(0);
36 EXPECT_FP_EQ_ALL_ROUNDING(aNaN, LIBC_NAMESPACE::asinf(inf));
37 EXPECT_MATH_ERRNO(EDOM);
39 EXPECT_FP_EQ_ALL_ROUNDING(aNaN, LIBC_NAMESPACE::asinf(neg_inf));
40 EXPECT_MATH_ERRNO(EDOM);
43 TEST_F(LlvmLibcAsinfTest, InFloatRange) {
44 constexpr uint32_t COUNT = 100'000;
45 constexpr uint32_t STEP = UINT32_MAX / COUNT;
46 for (uint32_t i = 0, v = 0; i <= COUNT; ++i, v += STEP) {
47 float x = FPBits(v).get_val();
48 if (FPBits(v).is_nan() || FPBits(v).is_inf())
49 continue;
50 ASSERT_MPFR_MATCH_ALL_ROUNDING(mpfr::Operation::Asin, x,
51 LIBC_NAMESPACE::asinf(x), 0.5);
55 TEST_F(LlvmLibcAsinfTest, SpecificBitPatterns) {
56 constexpr int N = 11;
57 constexpr uint32_t INPUTS[N] = {
58 0x3f000000, // x = 0.5f
59 0x3f3504f3, // x = sqrt(2)/2, FE_DOWNWARD
60 0x3f3504f4, // x = sqrt(2)/2, FE_UPWARD
61 0x3f5db3d7, // x = sqrt(3)/2, FE_DOWNWARD
62 0x3f5db3d8, // x = sqrt(3)/2, FE_UPWARD
63 0x3f800000, // x = 1.0f
64 0x40000000, // x = 2.0f
65 0x3d09bf86, // x = 0x1.137f0cp-5f
66 0x3de5fa1e, // x = 0x1.cbf43cp-4f
67 0x3f083a1a, // x = 0x1.107434p-1f
68 0x3f7741b6, // x = 0x1.ee836cp-1f
71 for (int i = 0; i < N; ++i) {
72 float x = FPBits(INPUTS[i]).get_val();
73 EXPECT_MPFR_MATCH_ALL_ROUNDING(mpfr::Operation::Asin, x,
74 LIBC_NAMESPACE::asinf(x), 0.5);
75 EXPECT_MPFR_MATCH_ALL_ROUNDING(mpfr::Operation::Asin, -x,
76 LIBC_NAMESPACE::asinf(-x), 0.5);