diff --git a/libc/config/linux/aarch64/entrypoints.txt b/libc/config/linux/aarch64/entrypoints.txt --- a/libc/config/linux/aarch64/entrypoints.txt +++ b/libc/config/linux/aarch64/entrypoints.txt @@ -206,6 +206,7 @@ # math.h entrypoints libc.src.math.acosf + libc.src.math.asin libc.src.math.asinf libc.src.math.atanf libc.src.math.atanhf diff --git a/libc/config/linux/x86_64/entrypoints.txt b/libc/config/linux/x86_64/entrypoints.txt --- a/libc/config/linux/x86_64/entrypoints.txt +++ b/libc/config/linux/x86_64/entrypoints.txt @@ -207,6 +207,7 @@ # math.h entrypoints libc.src.math.acosf + libc.src.math.asin libc.src.math.asinf libc.src.math.atanf libc.src.math.atanhf diff --git a/libc/config/windows/entrypoints.txt b/libc/config/windows/entrypoints.txt --- a/libc/config/windows/entrypoints.txt +++ b/libc/config/windows/entrypoints.txt @@ -107,6 +107,7 @@ # math.h entrypoints libc.src.math.acosf + libc.src.math.asin libc.src.math.asinf libc.src.math.atanf libc.src.math.atanhf diff --git a/libc/spec/stdc.td b/libc/spec/stdc.td --- a/libc/spec/stdc.td +++ b/libc/spec/stdc.td @@ -483,6 +483,7 @@ FunctionSpec<"acosf", RetValSpec, [ArgSpec]>, FunctionSpec<"asinf", RetValSpec, [ArgSpec]>, + FunctionSpec<"asin", RetValSpec, [ArgSpec]>, FunctionSpec<"atanf", RetValSpec, [ArgSpec]>, FunctionSpec<"atanhf", RetValSpec, [ArgSpec]>, diff --git a/libc/src/math/CMakeLists.txt b/libc/src/math/CMakeLists.txt --- a/libc/src/math/CMakeLists.txt +++ b/libc/src/math/CMakeLists.txt @@ -65,7 +65,10 @@ ) add_math_entrypoint_object(acosf) + +add_math_entrypoint_object(asin) add_math_entrypoint_object(asinf) + add_math_entrypoint_object(atanf) add_math_entrypoint_object(atanhf) diff --git a/libc/src/math/asin.h b/libc/src/math/asin.h new file mode 100644 --- /dev/null +++ b/libc/src/math/asin.h @@ -0,0 +1,18 @@ +//===-- Implementation header for asin --------------------------*- C++ -*-===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#ifndef LLVM_LIBC_SRC_MATH_ASIN_H +#define LLVM_LIBC_SRC_MATH_ASIN_H + +namespace __llvm_libc { + +double asin(double x); + +} // namespace __llvm_libc + +#endif // LLVM_LIBC_SRC_MATH_ASIN_H diff --git a/libc/src/math/generic/CMakeLists.txt b/libc/src/math/generic/CMakeLists.txt --- a/libc/src/math/generic/CMakeLists.txt +++ b/libc/src/math/generic/CMakeLists.txt @@ -1325,6 +1325,18 @@ -O3 ) +add_entrypoint_object( + asin + SRCS + asin.cpp + HDRS + ../asin.h + DEPENDS + .asinf + COMPILE_OPTIONS + -O3 +) + add_entrypoint_object( acosf SRCS diff --git a/libc/src/math/generic/asin.cpp b/libc/src/math/generic/asin.cpp new file mode 100644 --- /dev/null +++ b/libc/src/math/generic/asin.cpp @@ -0,0 +1,22 @@ +//===-- Double-precision asin function ------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#include "src/math/asin.h" +#include "src/math/asinf.h" + +#include "src/__support/common.h" + +namespace __llvm_libc { + +LLVM_LIBC_FUNCTION(double, asin, (double x)) { + // Place-holder implementation for double precision asin function. + // TODO: Implement correctly rounded asin function for double precision. + return static_cast(asinf(static_cast(x))); +} + +} // namespace __llvm_libc diff --git a/libc/test/src/math/CMakeLists.txt b/libc/test/src/math/CMakeLists.txt --- a/libc/test/src/math/CMakeLists.txt +++ b/libc/test/src/math/CMakeLists.txt @@ -1466,6 +1466,19 @@ libc.src.__support.FPUtil.fp_bits ) +add_fp_unittest( + asin_test + NEED_MPFR + SUITE + libc_math_unittests + SRCS + asin_test.cpp + DEPENDS + libc.include.errno + libc.src.errno.errno + libc.src.math.asin +) + add_fp_unittest( acosf_test NEED_MPFR diff --git a/libc/test/src/math/asin_test.cpp b/libc/test/src/math/asin_test.cpp new file mode 100644 --- /dev/null +++ b/libc/test/src/math/asin_test.cpp @@ -0,0 +1,41 @@ +//===-- Unittests for asin ------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#include "src/math/asin.h" +#include "utils/MPFRWrapper/MPFRUtils.h" +#include "utils/UnitTest/FPMatcher.h" +#include "utils/UnitTest/Test.h" +#include + +#include +#include + +using FPBits = __llvm_libc::fputil::FPBits; + +namespace mpfr = __llvm_libc::testing::mpfr; + +DECLARE_SPECIAL_CONSTANTS(double) + +TEST(LlvmLibcAsinTest, SpecialNumbers) { + errno = 0; + + EXPECT_FP_EQ(aNaN, __llvm_libc::asin(aNaN)); + EXPECT_MATH_ERRNO(0); + + EXPECT_FP_EQ(0.0, __llvm_libc::asin(0.0)); + EXPECT_MATH_ERRNO(0); + + EXPECT_FP_EQ(-0.0, __llvm_libc::asin(-0.0)); + EXPECT_MATH_ERRNO(0); + + EXPECT_FP_EQ(aNaN, __llvm_libc::asin(inf)); + EXPECT_MATH_ERRNO(EDOM); + + EXPECT_FP_EQ(aNaN, __llvm_libc::asin(neg_inf)); + EXPECT_MATH_ERRNO(EDOM); +}