util: add IEEE 754-2019 min/max number

fmin/fmax are not signed zero correct.

The name is taken from RDNA4's ISA, because the full IEEE name is a bit long.

Cc: mesa-stable

Reviewed-by: Alyssa Rosenzweig <alyssa.rosenzweig@intel.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/39137>
This commit is contained in:
Georg Lehmann 2026-01-03 10:25:11 +01:00 committed by Marge Bot
parent 1d120c1bf2
commit f68b891a81

View file

@ -333,6 +333,37 @@ uid(uint64_t ui)
return di.d;
}
/* Unlike C's fmax, this follows IEEE 754-2019
* maximumNumber rules (except sNaN vs qNaN behavior).
* This means, +0.0 is strictly greater than -0.0
* and NaN less than any number.
*/
static inline double
util_max_num(double a, double b)
{
/* Handle signed zero. (And sign bit.) */
if (a == b)
return uid(dui(a) & dui(b));
return fmax(a, b);
}
/* Unlike C's fmin, this follows IEEE 754-2019
* minimumNumber rules (except sNaN vs qNaN behavior).
* This means, -0.0 is strictly less than +0.0
* and NaN greater than any number.
*/
static inline double
util_min_num(double a, double b)
{
/* Handle signed zero. (Or sign bit.) */
if (a == b)
return uid(dui(a) | dui(b));
return fmin(a, b);
}
/**
* Convert uint8_t to float in [0, 1].
*/