[libcxx-commits] [libcxx] [libc++] Move std::abs into __math/abs.h (PR #139586)

Louis Dionne via libcxx-commits libcxx-commits at lists.llvm.org
Thu Jun 12 10:14:00 PDT 2025


================
@@ -39,6 +39,30 @@ template <class _A1, __enable_if_t<is_integral<_A1>::value, int> = 0>
   return __builtin_fabs((double)__x);
 }
 
+// abs
+
+[[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI inline float abs(float __x) _NOEXCEPT { return __builtin_fabsf(__x); }
+[[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI inline double abs(double __x) _NOEXCEPT { return __builtin_fabs(__x); }
+
+[[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI inline long double abs(long double __x) _NOEXCEPT {
+  return __builtin_fabsl(__x);
+}
+
+template <class = int>
----------------
ldionne wrote:

This is more than a move, it also changes how we handle the priority of integer overloads. Can you mention that (and why that's needed) in the commit message? I don't remember the reason anymore, and I think it's useful to document.

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


More information about the libcxx-commits mailing list