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

James Y Knight jyknight@google.com
Sun Dec 21 15:11:43 GMT 2025


On Sun, Dec 21, 2025 at 6:03 AM Vincent Lefevre <vincent@vinc17.net> wrote:
> On 2025-12-19 11:45:54 -0500, James Y Knight wrote:
> > The C standard (at least from C99 till C23) does _not_ require
> > fmin/fmax to order zeros by their sign, so glibc's previous behavior
> > was entirely standards-conforming.
>
> The glibc manual specifies more for its implementation:
>
>      The ‘fmin’ function returns the lesser of the two values X and Y.
>      It is similar to the expression
>           ((x) < (y) ? (x) : (y))
>      except that X and Y are only evaluated once.
>
> So, if x and y and both zeros, (x) < (y) is false, and y is returned.

I don't read "similar to" as requiring that the behavior precisely
emulate the given expression. But, if you DO consider that phrasing in
the manual to imply that glibc must implement fmin(-0.0, 0.0) == 0.0
and fmin(0.0, -0.0) == -0.0, then it violates its specification today
on aarch64, riscv, and loongarch. Those platforms are already
exhibiting the (preferable) behavior of treating -0.0 as below 0.0.

But thanks for pointing it out, I can update the manual to clarify.


More information about the Libc-alpha mailing list