[libc-commits] [libc] [libc][NFC] Introduce a Sign type for FPBits (PR #78500)

Clement Courbet via libc-commits libc-commits at lists.llvm.org
Thu Jan 18 02:12:39 PST 2024


================
@@ -20,23 +20,23 @@ namespace fputil {
 template <typename T, cpp::enable_if_t<cpp::is_floating_point_v<T>, int> = 0>
 LIBC_INLINE T abs(T x) {
   FPBits<T> bits(x);
-  bits.set_sign(0);
+  bits.set_sign(Sign::POS);
   return T(bits);
 }
 
 template <typename T, cpp::enable_if_t<cpp::is_floating_point_v<T>, int> = 0>
 LIBC_INLINE T fmin(T x, T y) {
-  FPBits<T> bitx(x), bity(y);
+  const FPBits<T> bitx(x), bity(y);
 
   if (bitx.is_nan()) {
     return y;
   } else if (bity.is_nan()) {
     return x;
-  } else if (bitx.get_sign() != bity.get_sign()) {
+  } else if (bitx.sign() != bity.sign()) {
     // To make sure that fmin(+0, -0) == -0 == fmin(-0, +0), whenever x and
     // y has different signs and both are not NaNs, we return the number
     // with negative sign.
-    return (bitx.get_sign() ? x : y);
+    return ((bitx.is_neg()) ? x : y);
----------------
legrosbuffle wrote:

[nit] You can drop the parens

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


More information about the libc-commits mailing list