[libc-commits] [libc] [llvm] Reland "[libc][math] Refactor fmaximum_mag_num family to header-only" (PR #194194)

via libc-commits libc-commits at lists.llvm.org
Sat Apr 25 16:35:30 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 h,cpp -- libc/shared/math/fmaximum_mag_num.h libc/shared/math/fmaximum_mag_numbf16.h libc/shared/math/fmaximum_mag_numf.h libc/src/__support/math/fmaximum_mag_num.h libc/src/__support/math/fmaximum_mag_numbf16.h libc/src/__support/math/fmaximum_mag_numf.h libc/shared/math.h libc/src/__support/FPUtil/BasicOperations.h libc/src/math/generic/fmaximum_mag_num.cpp libc/src/math/generic/fmaximum_mag_numbf16.cpp libc/src/math/generic/fmaximum_mag_numf.cpp libc/test/shared/shared_math_constexpr_test.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/src/__support/FPUtil/BasicOperations.h b/libc/src/__support/FPUtil/BasicOperations.h
index ca7b7db88..c633caff5 100644
--- a/libc/src/__support/FPUtil/BasicOperations.h
+++ b/libc/src/__support/FPUtil/BasicOperations.h
@@ -37,56 +37,56 @@ LIBC_INLINE constexpr cpp::enable_if_t<cpp::is_floating_point_v<T>, T>
 constexpr_max(T x, T y) {
   FPBits<T> x_bits(x);
   FPBits<T> y_bits(y);
-LIBC_INLINE constexpr cpp::enable_if_t<cpp::is_floating_point_v<T>, T>
-constexpr_max(T x, T y) {
-  FPBits<T> x_bits(x);
-  FPBits<T> y_bits(y);
-
-  // To make sure that fmax(+0, -0) == +0 == fmax(-0, +0), whenever x and y
-  // have different signs and both are not NaNs, we return the number with
-  // positive sign.
-  if (x_bits.sign() != y_bits.sign())
-    return x_bits.is_pos() ? x : y;
-  return x > y ? x : y;
-}
+  LIBC_INLINE constexpr cpp::enable_if_t<cpp::is_floating_point_v<T>, T>
+  constexpr_max(T x, T y) {
+    FPBits<T> x_bits(x);
+    FPBits<T> y_bits(y);
+
+    // To make sure that fmax(+0, -0) == +0 == fmax(-0, +0), whenever x and y
+    // have different signs and both are not NaNs, we return the number with
+    // positive sign.
+    if (x_bits.sign() != y_bits.sign())
+      return x_bits.is_pos() ? x : y;
+    return x > y ? x : y;
+  }
 
-template <typename T>
-LIBC_INLINE constexpr cpp::enable_if_t<cpp::is_floating_point_v<T>, T>
-max(T x, T y) {
-  return constexpr_max(x, y);
-}
+  template <typename T>
+  LIBC_INLINE constexpr cpp::enable_if_t<cpp::is_floating_point_v<T>, T> max(
+      T x, T y) {
+    return constexpr_max(x, y);
+  }
 
 #ifdef LIBC_TYPES_HAS_FLOAT16
 #if defined(__LIBC_USE_BUILTIN_FMAXF16_FMINF16)
-template <> LIBC_INLINE constexpr float16 max(float16 x, float16 y) {
-  if (cpp::is_constant_evaluated())
-    return constexpr_max(x, y);
-  return __builtin_fmaxf16(x, y);
-}
+  template <> LIBC_INLINE constexpr float16 max(float16 x, float16 y) {
+    if (cpp::is_constant_evaluated())
+      return constexpr_max(x, y);
+    return __builtin_fmaxf16(x, y);
+  }
 #elif !defined(LIBC_TARGET_ARCH_IS_AARCH64)
-template <> LIBC_INLINE constexpr float16 max(float16 x, float16 y) {
-  FPBits<float16> x_bits(x);
-  FPBits<float16> y_bits(y);
+  template <> LIBC_INLINE constexpr float16 max(float16 x, float16 y) {
+    FPBits<float16> x_bits(x);
+    FPBits<float16> y_bits(y);
 
-  int16_t xi = static_cast<int16_t>(x_bits.uintval());
-  int16_t yi = static_cast<int16_t>(y_bits.uintval());
-  return ((xi > yi) != (xi < 0 && yi < 0)) ? x : y;
-}
+    int16_t xi = static_cast<int16_t>(x_bits.uintval());
+    int16_t yi = static_cast<int16_t>(y_bits.uintval());
+    return ((xi > yi) != (xi < 0 && yi < 0)) ? x : y;
+  }
 #endif
 #endif // LIBC_TYPES_HAS_FLOAT16
 
 #if defined(__LIBC_USE_BUILTIN_FMAX_FMIN) && !defined(LIBC_TARGET_ARCH_IS_X86)
-template <> LIBC_INLINE constexpr float max(float x, float y) {
-  if (cpp::is_constant_evaluated())
-    return constexpr_max(x, y);
-  return __builtin_fmaxf(x, y);
-}
+  template <> LIBC_INLINE constexpr float max(float x, float y) {
+    if (cpp::is_constant_evaluated())
+      return constexpr_max(x, y);
+    return __builtin_fmaxf(x, y);
+  }
 
-template <> LIBC_INLINE constexpr double max(double x, double y) {
-  if (cpp::is_constant_evaluated())
-    return constexpr_max(x, y);
-  return __builtin_fmax(x, y);
-}
+  template <> LIBC_INLINE constexpr double max(double x, double y) {
+    if (cpp::is_constant_evaluated())
+      return constexpr_max(x, y);
+    return __builtin_fmax(x, y);
+  }
 #endif
 
 template <typename T>

``````````

</details>


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


More information about the libc-commits mailing list