[libc-commits] [libc] [libc][math] Implemented sinpif function (PR #97149)
via libc-commits
libc-commits at lists.llvm.org
Sat Jun 29 00:45:13 PDT 2024
github-actions[bot] wrote:
<!--LLVM CODE FORMAT COMMENT: {clang-format}-->
:warning: C/C++ code formatter, clang-format found issues in your code. :warning:
<details>
<summary>
You can test this locally with the following command:
</summary>
``````````bash
git-clang-format --diff 371e924605a45bcdfcba1aca939f127338dd91d8 16b93842602c88f5632dec0397bd28599f7da84d -- libc/src/math/generic/sinpif.cpp libc/src/math/sinpif.h libc/test/src/math/exhaustive/sinpif_test.cpp libc/test/src/math/sinpif_test.cpp libc/test/src/math/smoke/sinpif_test.cpp libc/src/math/generic/range_reduction_fma.h libc/src/math/generic/sincosf_utils.h libc/utils/MPFRWrapper/MPFRUtils.cpp libc/utils/MPFRWrapper/MPFRUtils.h
``````````
</details>
<details>
<summary>
View the diff from clang-format here.
</summary>
``````````diff
diff --git a/libc/src/math/generic/range_reduction_fma.h b/libc/src/math/generic/range_reduction_fma.h
index a270fdc003..1b36445275 100644
--- a/libc/src/math/generic/range_reduction_fma.h
+++ b/libc/src/math/generic/range_reduction_fma.h
@@ -44,7 +44,7 @@ LIBC_INLINE int64_t small_range_reduction(double x, double &y) {
LIBC_INLINE int64_t small_range_reduction_mul_pi(double x, double &y) {
double kd = fputil::nearest_integer(x * 32);
y = fputil::fma<double>(x, 32.0, -kd);
-
+
return static_cast<int64_t>(kd);
}
diff --git a/libc/src/math/generic/sincosf_utils.h b/libc/src/math/generic/sincosf_utils.h
index 5d93b28705..b11fbf573b 100644
--- a/libc/src/math/generic/sincosf_utils.h
+++ b/libc/src/math/generic/sincosf_utils.h
@@ -18,8 +18,8 @@
// using namespace LIBC_NAMESPACE::fma;
using LIBC_NAMESPACE::fma::FAST_PASS_BOUND;
using LIBC_NAMESPACE::fma::large_range_reduction;
-using LIBC_NAMESPACE::fma::small_range_reduction_mul_pi;
using LIBC_NAMESPACE::fma::small_range_reduction;
+using LIBC_NAMESPACE::fma::small_range_reduction_mul_pi;
#else
#include "range_reduction.h"
@@ -60,9 +60,9 @@ const double SIN_K_PI_OVER_32[64] = {
-0x1.917a6bc29b42cp-4,
};
-
static LIBC_INLINE void sincosf_poly_eval(int64_t k, double y, double &sin_k,
- double &cos_k, double &sin_y, double &cosm1_y) {
+ double &cos_k, double &sin_y,
+ double &cosm1_y) {
// After range reduction, k = round(x * 32 / pi) and y = (x * 32 / pi) - k.
// So k is an integer and -0.5 <= y <= 0.5.
// Then sin(x) = sin((k + y)*pi/32)
diff --git a/libc/src/math/generic/sinpif.cpp b/libc/src/math/generic/sinpif.cpp
index 2cedb6f290..078cf98ecd 100644
--- a/libc/src/math/generic/sinpif.cpp
+++ b/libc/src/math/generic/sinpif.cpp
@@ -1,4 +1,5 @@
-//===-- Single-precision sinpi function -------------------------------------===//
+//===-- Single-precision sinpi function
+//-------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
@@ -83,10 +84,11 @@ LLVM_LIBC_FUNCTION(float, sinpif, (float x)) {
// For signed zeros.
return x;
}
-
+
// For very small values we can approximate sinpi(x) with x * pi
- // An exhaustive test shows that this is accurate for |x| < 9.546391 × 10-8
- double xdpi = xd * 0x1.921fb54442d18p1;
+ // An exhaustive test shows that this is accurate for |x| < 9.546391 ×
+ // 10-8
+ double xdpi = xd * 0x1.921fb54442d18p1;
return static_cast<float>(xdpi);
}
@@ -106,7 +108,6 @@ LLVM_LIBC_FUNCTION(float, sinpif, (float x)) {
return static_cast<float>(xd * result);
}
-
if (LIBC_UNLIKELY(x_abs >= 0x7f80'0000U)) {
if (x_abs == 0x7f80'0000U) {
fputil::set_errno_if_required(EDOM);
@@ -129,4 +130,3 @@ LLVM_LIBC_FUNCTION(float, sinpif, (float x)) {
}
} // namespace LIBC_NAMESPACE
-
diff --git a/libc/src/math/sinpif.h b/libc/src/math/sinpif.h
index a5bef435ef..384c92d72f 100644
--- a/libc/src/math/sinpif.h
+++ b/libc/src/math/sinpif.h
@@ -1,4 +1,5 @@
-//===-- Implementation header for sinpif --------------------------*- C++ -*-===//
+//===-- Implementation header for sinpif --------------------------*- C++
+//-*-===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
diff --git a/libc/test/src/math/exhaustive/sinpif_test.cpp b/libc/test/src/math/exhaustive/sinpif_test.cpp
index 3c74c2872b..f255b0cb82 100644
--- a/libc/test/src/math/exhaustive/sinpif_test.cpp
+++ b/libc/test/src/math/exhaustive/sinpif_test.cpp
@@ -1,4 +1,5 @@
-//===-- Exhaustive test for sinpif ------------------------------------------===//
+//===-- Exhaustive test for sinpif
+//------------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
@@ -7,9 +8,9 @@
//===----------------------------------------------------------------------===//
#include "exhaustive_test.h"
+#include "mpfr.h"
#include "src/math/sinpif.h"
#include "utils/MPFRWrapper/MPFRUtils.h"
-#include "mpfr.h"
#include <sys/types.h>
namespace mpfr = LIBC_NAMESPACE::testing::mpfr;
diff --git a/libc/test/src/math/sinpif_test.cpp b/libc/test/src/math/sinpif_test.cpp
index 15f25b8657..87e6d0dc21 100644
--- a/libc/test/src/math/sinpif_test.cpp
+++ b/libc/test/src/math/sinpif_test.cpp
@@ -1,4 +1,5 @@
-//===-- Unittests for sinpif ------------------------------------------------===//
+//===-- Unittests for sinpif
+//------------------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
diff --git a/libc/test/src/math/smoke/sinpif_test.cpp b/libc/test/src/math/smoke/sinpif_test.cpp
index 9b3b6a6948..a114070620 100644
--- a/libc/test/src/math/smoke/sinpif_test.cpp
+++ b/libc/test/src/math/smoke/sinpif_test.cpp
@@ -1,4 +1,5 @@
-//===-- Unittests for sinpif ------------------------------------------------===//
+//===-- Unittests for sinpif
+//------------------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
``````````
</details>
https://github.com/llvm/llvm-project/pull/97149
More information about the libc-commits
mailing list