[libc-commits] [libc] [libc][math][c23] Implement canonicalize functions (PR #85940)
via libc-commits
libc-commits at lists.llvm.org
Thu Mar 21 21:30:37 PDT 2024
================
@@ -73,6 +76,54 @@ LIBC_INLINE T fdim(T x, T y) {
return (x > y ? x - y : 0);
}
+template <typename T, cpp::enable_if_t<cpp::is_floating_point_v<T>, int> = 0>
+LIBC_INLINE int canonicalize(T &cx, const T &x) {
+ FPBits<T> sx(x);
+ if (LIBC_UNLIKELY(sx.is_signaling_nan())) {
+ cx = FPBits<T>::quiet_nan(sx.sign(), sx.get_explicit_mantissa()).get_val();
+ raise_except_if_required(FE_INVALID);
+ return 1;
+ } else if constexpr (get_fp_type<T>() == FPType::X86_Binary80) {
----------------
lntue wrote:
since you already have early return, just remove the `else`, making it:
```
if (LIBC_UNLIKELY(sx.is_signaling_nan()) {
}
if constexpr (get_fp_type<T>() != FPType::X86_Binary80) {
cx = x;
return 0;
}
// x86-extended precision
...
```
https://github.com/llvm/llvm-project/pull/85940
More information about the libc-commits
mailing list