Hello, I do not feel confident sending a patch for the following reason: Glibc commit 85422c2acba83852396c9d9fd22ff0493e3606fe does contain a partial description of the specification that Glibc strives to implement: This patch makes them do so in cases that should include all the cases where such errno setting is required by glibc's goals for when to set errno (but not all cases of underflow where the result is nonzero and so glibc's goals do not require errno setting). However much remains unclear (for me!) about the specification that Glibc strives to implement. Does this mean that the specification is actually non-deterministic and that the manpage should contain a sentence saying “when the result of nextafter applied to distinct arguments x and y is subnormal, nextafter reserves the right to set errno to ERANGE but offers not guarantees of doing so; if the result is zero, errno is guaranteed to be set to ERANGE”? This does not make sense to me: how does one choose one's own specification for nextafter, over which one has full control, for a basic function that does not need to allocate resources, and make this specification non-deterministic? Does the non-determinism apply to the floating-point underflow exception as well? But then again, I notice that the current manpage description is already non-deterministic: a result that should be subnormal can be 0.0, confirming that I do not understand Glibc's goals. In these conditions I could not do a good job describing the specification that Glibc implements. Pascal ________________________________ From: Alejandro Colomar Sent: Friday, March 10, 2023 01:51 To: Pascal Cuoq; mtk.manpages@gmail.com Cc: linux-man@vger.kernel.org; Guillaume Cluzel; GNU C Library; Andreas Schwab Subject: Re: nextafter underflow and errno in Glibc Hello Pascal, On 3/8/23 19:10, Pascal Cuoq wrote: > Hello, > > in 2008 Michael Kerrisk reported that Glibc's nextafter implementation did not set errno as it should: > > https://sourceware.org/bugzilla/show_bug.cgi?id=6799 > > That bug was marked as “RESOLVED FIXED” in 2020 but there still exists a disagreement between what the current man page for nextafter at https://man7.org/linux/man-pages/man3/nextafter.3.html says, namely: > > If x is not equal to y, and the correct function result would be > subnormal, zero, or underflow, a range error occurs, and either > the correct value (if it can be represented), or 0.0, is > returned. > … > Range error: result is subnormal or underflows > errno is set to ERANGE. An underflow floating-point > exception (FE_UNDERFLOW) is raised. > > … and what Glibc's implementation does for nextafter(0., 1.). > > This has been reported by myself in January of 2023: > > https://sourceware.org/bugzilla/show_bug.cgi?id=30040 > > As of this writing, the Glibc maintainers' stance appears to be that this behavior is intentional because the specification that Glibc intends to implement only mandates setting errno when the result is zero, and apparently allows setting it or not when the result is 0x1.0p-1074, depending on whether this value was obtained by going one step up from 0.0 or one step down from 0x2.0p-1074. > > If the Glibc maintainers do not consider the current behavior a bug, then this should be noted somehow in the nextafter man page. Would you please send a patch for the manual page? You can find the guidelines for that here: . You can clone the git repository from here: If you send a patch, please CC the folowing: Cc: Andreas Schwab Cc: Thanks, Alex > > Regards, > > Pascal > -- GPG key fingerprint: A9348594CE31283A826FBDD8D57633D441E25BB5