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 @@ -141,6 +141,9 @@ libc.src.math.modf libc.src.math.modff libc.src.math.modfl + libc.src.math.nearbyint + libc.src.math.nearbyintf + libc.src.math.nearbyintl libc.src.math.remainderf libc.src.math.remainder libc.src.math.remainderl diff --git a/libc/spec/stdc.td b/libc/spec/stdc.td --- a/libc/spec/stdc.td +++ b/libc/spec/stdc.td @@ -390,6 +390,10 @@ FunctionSpec<"trunc", RetValSpec, [ArgSpec]>, FunctionSpec<"truncf", RetValSpec, [ArgSpec]>, FunctionSpec<"truncl", RetValSpec, [ArgSpec]>, + + FunctionSpec<"nearbyint", RetValSpec, [ArgSpec]>, + FunctionSpec<"nearbyintf", RetValSpec, [ArgSpec]>, + FunctionSpec<"nearbyintl", 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 @@ -416,6 +416,42 @@ -O2 ) +add_entrypoint_object( + nearbyint + SRCS + nearbyint.cpp + HDRS + nearbyint.h + DEPENDS + libc.utils.FPUtil.fputil + COMPILE_OPTIONS + -O2 +) + +add_entrypoint_object( + nearbyintf + SRCS + nearbyintf.cpp + HDRS + nearbyintf.h + DEPENDS + libc.utils.FPUtil.fputil + COMPILE_OPTIONS + -O2 +) + +add_entrypoint_object( + nearbyintl + SRCS + nearbyintl.cpp + HDRS + nearbyintl.h + DEPENDS + libc.utils.FPUtil.fputil + COMPILE_OPTIONS + -O2 +) + add_object_library( exp_utils HDRS diff --git a/libc/src/math/nearbyint.h b/libc/src/math/nearbyint.h new file mode 100644 --- /dev/null +++ b/libc/src/math/nearbyint.h @@ -0,0 +1,18 @@ +//===-- Implementation header for nearbyint ---------------------*- 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_NEARBYINT_H +#define LLVM_LIBC_SRC_MATH_NEARBYINT_H + +namespace __llvm_libc { + +double nearbyint(double x); + +} // namespace __llvm_libc + +#endif // LLVM_LIBC_SRC_MATH_NEARBYINT_H diff --git a/libc/src/math/nearbyint.cpp b/libc/src/math/nearbyint.cpp new file mode 100644 --- /dev/null +++ b/libc/src/math/nearbyint.cpp @@ -0,0 +1,18 @@ +//===-- Implementation of nearbyint 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/__support/common.h" +#include "utils/FPUtil/NearestIntegerOperations.h" + +namespace __llvm_libc { + +double LLVM_LIBC_ENTRYPOINT(nearbyint)(double x) { + return fputil::roundUsingCurrentRoundingMode(x); +} + +} // namespace __llvm_libc diff --git a/libc/src/math/nearbyintf.h b/libc/src/math/nearbyintf.h new file mode 100644 --- /dev/null +++ b/libc/src/math/nearbyintf.h @@ -0,0 +1,18 @@ +//===-- Implementation header for nearbyintf --------------------*- 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_NEARBYINTF_H +#define LLVM_LIBC_SRC_MATH_NEARBYINTF_H + +namespace __llvm_libc { + +float nearbyintf(float x); + +} // namespace __llvm_libc + +#endif // LLVM_LIBC_SRC_MATH_NEARBYINTF_H diff --git a/libc/src/math/nearbyintf.cpp b/libc/src/math/nearbyintf.cpp new file mode 100644 --- /dev/null +++ b/libc/src/math/nearbyintf.cpp @@ -0,0 +1,18 @@ +//===-- Implementation of nearbyintf 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/__support/common.h" +#include "utils/FPUtil/NearestIntegerOperations.h" + +namespace __llvm_libc { + +float LLVM_LIBC_ENTRYPOINT(nearbyintf)(float x) { + return fputil::roundUsingCurrentRoundingMode(x); +} + +} // namespace __llvm_libc diff --git a/libc/src/math/nearbyintl.h b/libc/src/math/nearbyintl.h new file mode 100644 --- /dev/null +++ b/libc/src/math/nearbyintl.h @@ -0,0 +1,18 @@ +//===-- Implementation header for nearbyintl --------------------*- 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_NEARBYINTL_H +#define LLVM_LIBC_SRC_MATH_NEARBYINTL_H + +namespace __llvm_libc { + +long double nearbyintl(long double x); + +} // namespace __llvm_libc + +#endif // LLVM_LIBC_SRC_MATH_NEARBYINTL_H diff --git a/libc/src/math/nearbyintl.cpp b/libc/src/math/nearbyintl.cpp new file mode 100644 --- /dev/null +++ b/libc/src/math/nearbyintl.cpp @@ -0,0 +1,18 @@ +//===-- Implementation of nearbyintl 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/__support/common.h" +#include "utils/FPUtil/NearestIntegerOperations.h" + +namespace __llvm_libc { + +long double LLVM_LIBC_ENTRYPOINT(nearbyintl)(long double x) { + return fputil::roundUsingCurrentRoundingMode(x); +} + +} // namespace __llvm_libc