[PATCH] math: Order signed zeros in fmin and fmax.

James Y Knight jyknight@google.com
Sun Dec 21 04:31:37 GMT 2025


On Sat, Dec 20, 2025 at 12:53 PM Wilco Dijkstra <Wilco.Dijkstra@arm.com> wrote:
> Does this work on all targets that have hardware fmin/fmax?

I believe the patch results in the desired behavior on all targets,
even though it modifies only the i386, i686, x86_64, and the generic C
implementation.

The additional targets in glibc which don't use the generic C
implementation are:
- riscv
- loongarch (via setting USE_F{MIN,MAX}{,F}_BUILTIN)
- aarch64 (via setting USE_F{MIN,MAX}{,F}_BUILTIN)

On these architectures, the operation is already implemented by a
single hardware instruction with the desired behavior; no changes are
required.

> There are at least
> 3 different variations of fmin/fmax in the IEEE standard, so I'm wondering whether
> they do agree on how to handle signed zeroes... If it works on all modern targets,
> that's great, but that's not clear from your description because ISAs typically
> follow IEEE specs.

Yes, the other variations of floating-point min/max are fminimum,
fminimum_mag, fminimum_num, fminimum_mag_num (and their corresponding
maximums). Those functions are required to order signed zeros by the C
standard, unlike fmin/fmax where it is only recommended.

James


More information about the Libc-alpha mailing list