[libc-commits] [libc] [libc][math][c23] Add {totalorder, totalordermag}f16 C23 math functions (PR #95014)

via libc-commits libc-commits at lists.llvm.org
Mon Jun 10 18:16:08 PDT 2024


================
@@ -240,6 +240,57 @@ LIBC_INLINE int canonicalize(T &cx, const T &x) {
   return 0;
 }
 
+template <typename T>
+LIBC_INLINE cpp::enable_if_t<cpp::is_floating_point_v<T>, bool>
+totalorder(const T *x, const T *y) {
+  using FPBits = FPBits<T>;
+  FPBits xbits(*x);
+  FPBits ybits(*y);
+
+  if (LIBC_UNLIKELY(xbits.is_zero() && ybits.is_zero() || xbits.is_nan() ||
----------------
lntue wrote:

I think this function could be simplified to:
```
using signed_t = cpp::make_signed_t<FPBits::StorageType>;
signed_t x_signed = static_cast<signed_t>(xbits.uintval());
signed_t y_signed = static_cast<signed_t>(ybits.uintval());
bool both_neg = (x_bits.uintval() & y_bits.uintval & FPBits::SIGN_MASK) != 0;
return (x_signed <= y_signed) != both_neg;
```

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


More information about the libc-commits mailing list