[libc-commits] [libc] [libc][math][c23] Add rsqrtf16() function (PR #137545)

via libc-commits libc-commits at lists.llvm.org
Sun Apr 27 12:59:41 PDT 2025


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 HEAD~1 HEAD --extensions cpp,h -- libc/src/math/generic/rsqrtf16.cpp libc/src/math/rsqrtf16.h libc/test/src/math/rsqrtf16_test.cpp libc/test/src/math/smoke/rsqrtf16_test.cpp libc/utils/MPFRWrapper/MPCommon.cpp libc/utils/MPFRWrapper/MPCommon.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/rsqrtf16.cpp b/libc/src/math/generic/rsqrtf16.cpp
index 930c8f6fc..8e97ec896 100644
--- a/libc/src/math/generic/rsqrtf16.cpp
+++ b/libc/src/math/generic/rsqrtf16.cpp
@@ -35,7 +35,7 @@ LLVM_LIBC_FUNCTION(float16, rsqrtf16, (float16 x)) {
     }
     return x;
   }
-  
+
   // |x| = 0
   if (LIBC_UNLIKELY(x_abs == 0x0)) {
     fputil::raise_except_if_required(FE_DIVBYZERO);
@@ -44,7 +44,7 @@ LLVM_LIBC_FUNCTION(float16, rsqrtf16, (float16 x)) {
   }
 
   // -inf <= x < 0
-  if (LIBC_UNLIKELY(x_sign == 1)) {  
+  if (LIBC_UNLIKELY(x_sign == 1)) {
     fputil::raise_except_if_required(FE_INVALID);
     fputil::set_errno_if_required(EDOM);
     return FPBits::quiet_nan().get_val();
@@ -54,13 +54,14 @@ LLVM_LIBC_FUNCTION(float16, rsqrtf16, (float16 x)) {
   if (LIBC_UNLIKELY(xbits.is_inf())) {
     return fputil::cast<float16>(0.0f);
   }
-  
+
   // x = 1 => rsqrt(x) = 1
   if (LIBC_UNLIKELY(x_u == 0x1)) {
     return fputil::cast<float16>(1.0f);
   }
 
-  // x is valid, estimate the result - below is temporary solution for just testing
+  // x is valid, estimate the result - below is temporary solution for just
+  // testing
   float xf = x;
   return fputil::cast<float16>(1.0f / xf);
 }
diff --git a/libc/test/src/math/smoke/rsqrtf16_test.cpp b/libc/test/src/math/smoke/rsqrtf16_test.cpp
index eb429d3db..d50d8ee0a 100644
--- a/libc/test/src/math/smoke/rsqrtf16_test.cpp
+++ b/libc/test/src/math/smoke/rsqrtf16_test.cpp
@@ -17,8 +17,7 @@ TEST_F(LlvmLibcRsqrtf16Test, SpecialNumbers) {
   EXPECT_FP_EQ(aNaN, LIBC_NAMESPACE::rsqrtf16(aNaN));
   EXPECT_MATH_ERRNO(0);
 
-  EXPECT_FP_EQ_WITH_EXCEPTION(aNaN, LIBC_NAMESPACE::rsqrtf16(sNaN),
-                              FE_INVALID);
+  EXPECT_FP_EQ_WITH_EXCEPTION(aNaN, LIBC_NAMESPACE::rsqrtf16(sNaN), FE_INVALID);
   EXPECT_MATH_ERRNO(0);
 
   EXPECT_FP_EQ(aNaN, LIBC_NAMESPACE::rsqrtf16(0.0f));

``````````

</details>


https://github.com/llvm/llvm-project/pull/137545


More information about the libc-commits mailing list