         return a;
     else if (half_isnan(b.value))
         return b;
-    else if ((half_greater_than(a.value, b.value)) ||
+    else if ((half_less(a.value, b.value)) ||
              (half_equal(a.value, b.value) && (b.key < a.key)))
         return b;
     else

        return a;
    else if (half_isnan(b.value))
        return b;
    else if ((half_greater_than(b.value, a.value)) ||
             (half_equal(a.value, b.value) && (b.key < a.key)))
        return b;
    else

    // NumPy behavior: NaN is always chosen!
    if (half_isnan(a)) {return a;}
    else if (half_isnan(b)) {return b;}
    else if (half_less(a, b)) {return a;}
    else {return a;}
}
#endif
