[libc-commits] [libc] [llvm] [libc][math] Refactor log to header-only shared math (PR #175395)

via libc-commits libc-commits at lists.llvm.org
Sat Jan 10 14:47:24 PST 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/log.h libc/src/__support/math/log.h libc/shared/math.h libc/src/math/generic/log.cpp 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/shared/math.h b/libc/shared/math.h
index 704ff8b41..010658357 100644
--- a/libc/shared/math.h
+++ b/libc/shared/math.h
@@ -63,9 +63,9 @@
 #include "math/ldexpf.h"
 #include "math/ldexpf128.h"
 #include "math/ldexpf16.h"
+#include "math/log.h"
 #include "math/rsqrtf.h"
 #include "math/rsqrtf16.h"
-#include "math/log.h"
 #include "math/sin.h"
 
 #endif // LLVM_LIBC_SHARED_MATH_H
diff --git a/libc/shared/math/log.h b/libc/shared/math/log.h
index 41f8c3cc4..ca940512a 100644
--- a/libc/shared/math/log.h
+++ b/libc/shared/math/log.h
@@ -15,7 +15,7 @@ namespace LIBC_NAMESPACE_DECL {
 
 namespace shared {
 using math::log;
-} //namespace shared
+} // namespace shared
 
 } // namespace LIBC_NAMESPACE_DECL
 
diff --git a/libc/src/__support/math/log.h b/libc/src/__support/math/log.h
index 0f42e5224..37072f0f2 100644
--- a/libc/src/__support/math/log.h
+++ b/libc/src/__support/math/log.h
@@ -1,6 +1,7 @@
 #ifndef LLVM_LIBC_SRC___SUPPORT_MATH_LOG_H
 #define LLVM_LIBC_SRC___SUPPORT_MATH_LOG_H
 
+#include "log_range_reduction.h"
 #include "src/__support/FPUtil/FEnvImpl.h"
 #include "src/__support/FPUtil/FPBits.h"
 #include "src/__support/FPUtil/PolyEval.h"
@@ -11,10 +12,8 @@
 #include "src/__support/integer_literals.h"
 #include "src/__support/macros/config.h"
 #include "src/__support/macros/optimization.h" // LIBC_UNLIKELY
-#include "log_range_reduction.h"
 #include "src/__support/math/common_constants.h"
 
-
 namespace LIBC_NAMESPACE_DECL {
 
 // 128-bit precision dyadic floating point numbers.
@@ -707,7 +706,7 @@ constexpr Float128 BIG_COEFFS[3]{
     {Sign::NEG, -128, 0x80000000'00000000'00000000'00000000_u128},
 };
 
-#endif //LLVM_LIBC_SRC___SUPPORT_MATH_LOG_H
+#endif // LLVM_LIBC_SRC___SUPPORT_MATH_LOG_H
 
 // Reuse the output of the fast pass range reduction.
 // -2^-8 <= m_x < 2^-7
@@ -731,8 +730,8 @@ LIBC_INLINE double log_accurate(int e_x, int index, double m_x) {
   return static_cast<double>(r);
 }
 
-LIBC_INLINE double log(double x){
-     using FPBits_t = typename fputil::FPBits<double>;
+LIBC_INLINE double log(double x) {
+  using FPBits_t = typename fputil::FPBits<double>;
 
   FPBits_t xbits(x);
   uint64_t x_u = xbits.uintval();
@@ -843,4 +842,4 @@ LIBC_INLINE double log(double x){
 
 } // namespace LIBC_NAMESPACE_DECL
 
-#endif //LLVM_LIBC_SRC___SUPPORT_MATH_LOG_H
+#endif // LLVM_LIBC_SRC___SUPPORT_MATH_LOG_H
diff --git a/libc/src/math/generic/log.cpp b/libc/src/math/generic/log.cpp
index 378ec00b4..aae0163a1 100644
--- a/libc/src/math/generic/log.cpp
+++ b/libc/src/math/generic/log.cpp
@@ -10,8 +10,6 @@
 #include "src/__support/math/log.h"
 
 namespace LIBC_NAMESPACE_DECL {
-LLVM_LIBC_FUNCTION(double, log, (double x)) {
-  return math::log(x);
-}
- 
+LLVM_LIBC_FUNCTION(double, log, (double x)) { return math::log(x); }
+
 } // namespace LIBC_NAMESPACE_DECL

``````````

</details>


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


More information about the libc-commits mailing list