[flang] Accept polymorphic component element in storage_size
[llvm-project.git] / libc / test / src / math / asinf_test.cpp
blob890f21f51612e08df83f7d3359295ac46149aa4f
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 "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"
15 #include <math.h>
17 #include <errno.h>
18 #include <stdint.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) {
27 errno = 0;
29 EXPECT_FP_EQ(aNaN, __llvm_libc::asinf(aNaN));
30 EXPECT_MATH_ERRNO(0);
32 EXPECT_FP_EQ(0.0f, __llvm_libc::asinf(0.0f));
33 EXPECT_MATH_ERRNO(0);
35 EXPECT_FP_EQ(-0.0f, __llvm_libc::asinf(-0.0f));
36 EXPECT_MATH_ERRNO(0);
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))
51 continue;
52 ASSERT_MPFR_MATCH_ALL_ROUNDING(mpfr::Operation::Asin, x,
53 __llvm_libc::asinf(x), 0.5);
57 TEST(LlvmLibcAsinfTest, SpecificBitPatterns) {
58 constexpr int N = 11;
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);