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

Muhammad Bassiouni via libc-commits libc-commits at lists.llvm.org
Fri Apr 24 07:49:03 PDT 2026


================
@@ -47,11 +48,17 @@ LIBC_INLINE cpp::enable_if_t<cpp::is_floating_point_v<T>, T> max(T x, T y) {
 
 #ifdef LIBC_TYPES_HAS_FLOAT16
 #if defined(__LIBC_USE_BUILTIN_FMAXF16_FMINF16)
-template <> LIBC_INLINE float16 max(float16 x, float16 y) {
+template <> LIBC_INLINE constexpr float16 max(float16 x, float16 y) {
+  if (cpp::is_constant_evaluated()) {
+    FPBits<float16> x_bits(x), y_bits(y);
+    if (x_bits.sign() != y_bits.sign())
+      return x_bits.is_pos() ? x : y;
+    return x > y ? x : y;
+  }
----------------
bassiounix wrote:

I'd prefer to extract the common code to another function and call it inside the body instead of repeating the same logic twice, maybe call it `constant_max` or something suitable

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


More information about the libc-commits mailing list