     // 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 b;}
+    else { return half_less(a, b) ? a : b; }
 }
 #endif
 

#include <cub/device/device_spmv.cuh>
#include <cub/device/device_scan.cuh>
#include <cub/device/device_histogram.cuh>
using namespace cub;
#else
#include <hipcub/device/device_reduce.hpp>
#include <hipcub/device/device_segmented_reduce.hpp>
//#include <hipcub/device/device_spmv.hpp>  // doesn't exist
#include <hipcub/device/device_scan.hpp>
#include <hipcub/device/device_histogram.hpp>
using namespace hipcub;
#endif


#ifndef CUPY_USE_HIP
/* ------------------------------------ Minimum boilerplate to support complex numbers ------------------------------------ */
// - This works only because all data fields in the *Traits struct are not
//   used in <cub/device/device_reduce.cuh>.
// - The Max() and Lowest() below are chosen to comply with NumPy's lexical
//   ordering; note that std::numeric_limits<T> does not support complex
//   numbers as in general the comparison is ill defined.
// - DO NOT USE THIS STUB for supporting CUB sorting!!!!!!
template <>
struct FpLimits<complex<float>>
{

    // - isnan() and max() are defined in cupy/complex.cuh
    if (isnan(a)) {return a;}
    else if (isnan(b)) {return b;}
    else {return a < b ? b : a;}
}

#if (__CUDACC_VER_MAJOR__ > 9 || (__CUDACC_VER_MAJOR__ == 9 && __CUDACC_VER_MINOR__ == 2)) \
