On Fri, 2023-11-24 at 17:46 +0800, chenglulu wrote:
> It's just that I'm confused that the description of rint in n2310,
> including Joseph's email,
> all say that rint will not set errno, but linux-man says "which might
> set errno to ERANGE" .
Annex F has:
The C floating types match the IEC 60559 formats as follows:
- The float type matches the IEC 60559 single format.
- The double type matches the IEC 60559 double format.
With these constraints rint and rintf just cannot have a range or domain
error. So Annex F does not say rint may set errno. Linux-man says:
ERRORS
No errors occur. POSIX.1‐2001 documents a range error for overflows,
but see NOTES.
It's because POSIX does not mandates float/double to match the IEC 60559
formats, thus a range error may happen with some strange floating point
formats. The NOTES says "this won't happen for IEC 60559 formats".
For lrint, N2310 says:
If the rounded value is outside the range of the return type, the
numeric result is unspecified and a domain error or range error may
occur.
So a EDOM or ERANGE may be set. On the contrary, the man page says:
The following errors can occur:
Domain error: x is a NaN or infinite, or the rounded value is too large
An invalid floating‐point exception (FE_INVALID) is raised.
These functions do not set errno.
The last paragraph is Glibc-specific, and it's considered a Glibc bug
(https://sourceware.org/bugzilla/show_bug.cgi?id=6798).
--
Xi Ruoyao <[email protected]>
School of Aerospace Science and Technology, Xidian University