Hi,
On Wed, 28 Jan 2015, Tobias Burnus wrote:
> I first want to point to POSIX, which has:
>
> "floor, floorf, floorl - floor function" [...]
> "An application wishing to check for error situations should set errno to
> zero and call feclearexcept(FE_ALL_EXCEPT) before calling these functions.
> On return, if errno is non-zero or fetestexcept(FE_INVALID |
> FE_DIVBYZERO | FE_OVERFLOW | FE_UNDERFLOW) is non-zero, an error has
> occurred."
>
> No one seems to care about the "errno" handling (and prefers to use the
> trapping information directly), thus, I wouldn't be surprised if most
> libc do not set errno.
That is because the error conditions that POSIX allows simply can't happen
with the IEEE float formats that are in use. From the glibc manpage for
floor:
NOTES
SUSv2 and POSIX.1-2001 contain text about overflow (which might set
errno to ERANGE, or raise an FE_OVERFLOW exception). In practice, the
result cannot overflow on any current machine, so this error-handling
stuff is just nonsense. (More precisely, overflow can happen only when
the maximum value of the exponent is smaller than the number of man-
tissa bits. For the IEEE-754 standard 32-bit and 64-bit floating-point
numbers the maximum value of the exponent is 128 (respectively, 1024),
and the number of mantissa bits is 24 (respectively, 53).)
Hence, GCC guarding the transformation is simply a bit too cautious.
Ciao,
Michael.