[libc-commits] [libc] [libc][math][c23] add c23 floating point fmaximum and fminimum functions. (PR #86016)
Job Henandez Lara via libc-commits
libc-commits at lists.llvm.org
Sun Mar 24 14:40:18 PDT 2024
================
@@ -58,6 +58,102 @@ LIBC_INLINE T fmax(T x, T y) {
}
}
+template <typename T, cpp::enable_if_t<cpp::is_floating_point_v<T>, int> = 0>
+LIBC_INLINE T fmaximum(T x, T y) {
+ FPBits<T> bitx(x), bity(y);
+
+ if (bitx.is_nan())
+ return x;
+ if (bity.is_nan())
+ return y;
+ if (bitx.sign() != bity.sign())
+ return (bitx.is_neg() ? y : x);
+ return x > y ? x : y;
+}
+
+template <typename T, cpp::enable_if_t<cpp::is_floating_point_v<T>, int> = 0>
+LIBC_INLINE T fminimum(T x, T y) {
+ const FPBits<T> bitx(x), bity(y);
+
+ if (bitx.is_nan())
+ return x;
+ if (bity.is_nan())
+ return y;
+ if (bitx.sign() != bity.sign())
+ return (bitx.is_neg()) ? x : y;
+ return x < y ? x : y;
+}
+
+template <typename T, cpp::enable_if_t<cpp::is_floating_point_v<T>, int> = 0>
+LIBC_INLINE T fmaximum_num(T x, T y) {
+ FPBits<T> bitx(x), bity(y);
+
+ if (bitx.is_nan())
----------------
Jobhdez wrote:
Is my handling of the case associated with raising the exception correct? Because I used you example and I’m getting `which is 0 to be greater or equal to 4`. I also tried to return a quiet nan but same thing happened
https://github.com/llvm/llvm-project/pull/86016
More information about the libc-commits
mailing list