[llvm] APFloat: Add minimumnum and maximumnum (PR #96304)

YunQiang Su via llvm-commits llvm-commits at lists.llvm.org
Fri Jun 21 07:26:50 PDT 2024


================
@@ -1483,6 +1483,19 @@ inline APFloat minimum(const APFloat &A, const APFloat &B) {
   return B < A ? B : A;
 }
 
+/// Implements IEEE 754-2019 minimumNumber semantics. Returns the smaller
+/// of 2 arguments, not propagating NaNs and treating -0 as less than +0.
+LLVM_READONLY
+inline APFloat minimumnum(const APFloat &A, const APFloat &B) {
+  if (A.isNaN())
+    return B.isNaN() ? B.makeQuiet() : B;
----------------
wzssyqa wrote:

> Is there a reason to prefer B's payload to A's if both are nan?

Just as Thorsten said, I am lazy, so that there is always B in this line.
If we prefer A, we will have `if (B.isNaN())` in the first line, it is not so friendly to my brain ;)

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


More information about the llvm-commits mailing list