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

Vincent Lefevre vincent@vinc17.net
Sun Dec 21 17:09:26 GMT 2025


On 2025-12-21 10:11:43 -0500, James Y Knight wrote:
> 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.

As I read it, the differences with the emulated expression are given
by the "except" phrase (or later), i.e. "except that X and Y are only
evaluated once". For the differences, mentioning the the number of
evaluations but not the ignored sign of zero is very misleading.

(The case of NaN was already specified in the subsequent paragraph.)

> 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.

OK.

-- 
Vincent Lefèvre <vincent@vinc17.net> - Web: <https://www.vinc17.net/>
100% accessible validated (X)HTML - Blog: <https://www.vinc17.net/blog/>
Work: CR INRIA - computer arithmetic / Pascaline project (LIP, ENS-Lyon)


More information about the Libc-alpha mailing list