This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: Why is floor() only compiled to roundsd when using -funsafe-math-optimizations?
- From: Michael Matz <matz at suse dot de>
- To: Tobias Burnus <tobias dot burnus at physik dot fu-berlin dot de>
- Cc: Fredrik Tolf <fredrik at dolda2000 dot com>, gcc at gcc dot gnu dot org, Jay Foad <jay dot foad at gmail dot com>
- Date: Wed, 28 Jan 2015 18:09:10 +0100 (CET)
- Subject: Re: Why is floor() only compiled to roundsd when using -funsafe-math-optimizations?
- Authentication-results: sourceware.org; auth=none
- References: <20150128155545 dot GA6399 at physik dot fu-berlin dot de>
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.