[libc-commits] [libc] [libc][math] Impl bfloat16 lgamma function. (PR #199312)

via libc-commits libc-commits at lists.llvm.org
Sat May 23 03:02:13 PDT 2026


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 origin/main HEAD --extensions cpp,h -- libc/shared/math/lgammabf16.h libc/src/__support/math/lgammabf16.h libc/src/math/generic/lgammabf16.cpp libc/src/math/lgammabf16.h libc/test/src/math/exhaustive/lgammabf16_test.cpp libc/test/src/math/lgammabf16_test.cpp libc/test/src/math/smoke/lgammabf16_test.cpp libc/shared/math.h libc/test/shared/shared_math_test.cpp --diff_from_common_commit
``````````

:warning:
The reproduction instructions above might return results for more than one PR
in a stack if you are using a stacked PR workflow. You can limit the results by
changing `origin/main` to the base branch/commit you want to compare against.
:warning:

</details>

<details>
<summary>
View the diff from clang-format here.
</summary>

``````````diff
diff --git a/libc/src/__support/math/lgammabf16.h b/libc/src/__support/math/lgammabf16.h
index a2cffe0c5..9f2fb2013 100644
--- a/libc/src/__support/math/lgammabf16.h
+++ b/libc/src/__support/math/lgammabf16.h
@@ -28,7 +28,8 @@ namespace math {
 // lgammabf16(x) computes log(|Gamma(x)|) in bfloat16.
 //
 // Strategy:
-//   - Special cases: NaN, 0, negative integers, +Inf or -Inf -> handled explicitly.
+//   - Special cases: NaN, 0, negative integers, +Inf or -Inf -> handled
+//   explicitly.
 //   - For all other values: promote bfloat16 -> float, compute lgammaf,
 //     narrow back to bfloat16.
 //
diff --git a/libc/test/src/math/lgammabf16_test.cpp b/libc/test/src/math/lgammabf16_test.cpp
index d7916f92f..c109a8c8d 100644
--- a/libc/test/src/math/lgammabf16_test.cpp
+++ b/libc/test/src/math/lgammabf16_test.cpp
@@ -6,8 +6,8 @@
 //
 //===----------------------------------------------------------------------===//
 
-#include "src/math/lgammabf16.h"
 #include "src/__support/FPUtil/bfloat16.h"
+#include "src/math/lgammabf16.h"
 #include "test/UnitTest/FEnvSafeTest.h"
 #include "test/UnitTest/FPMatcher.h"
 #include "test/UnitTest/Test.h"
@@ -33,13 +33,14 @@ TEST_F(LlvmLibcLgammaBf16Test, SpecialNumbers) { test_special_numbers(); }
 TEST_F(LlvmLibcLgammaBf16Test, InBFloat16Range) {
   constexpr uint16_t COUNT = 10000;
   constexpr uint32_t STEP = 0x7F80U / COUNT;
-  
+
   for (uint32_t i = 0, v = 0; i <= COUNT; ++i, v += STEP) {
-    bfloat16 x = LIBC_NAMESPACE::cpp::bit_cast<bfloat16>(static_cast<uint16_t>(v));
+    bfloat16 x =
+        LIBC_NAMESPACE::cpp::bit_cast<bfloat16>(static_cast<uint16_t>(v));
     if (LIBC_NAMESPACE::fputil::isnan(x) || LIBC_NAMESPACE::fputil::isinf(x))
       continue;
 
-    ASSERT_MPFR_MATCH(mpfr::Operation::Lgamma, x,
-                      LIBC_NAMESPACE::lgammabf16(x), 0.5);
+    ASSERT_MPFR_MATCH(mpfr::Operation::Lgamma, x, LIBC_NAMESPACE::lgammabf16(x),
+                      0.5);
   }
 }

``````````

</details>


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


More information about the libc-commits mailing list