This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
RE: float to int conversion
- From: "Warlich, Christof" <christof dot warlich at siemens dot com>
- To: Vincent Lefevre <vincent+gcc at vinc17 dot org>, "gcc-help at gcc dot gnu dot org" <gcc-help at gcc dot gnu dot org>
- Date: Mon, 22 Apr 2013 12:01:18 +0000
- Subject: RE: float to int conversion
- References: <6D83E89737156549AEA25EF9ED712C5DD11B at DEFTHW99EK1MSX dot ww902 dot siemens dot net> <5174F57B dot 4080701 at redhat dot com> <6D83E89737156549AEA25EF9ED712C5DD14A at DEFTHW99EK1MSX dot ww902 dot siemens dot net> <20130422120325 dot 6168e915 at ketmar dot no-ip dot org> <6D83E89737156549AEA25EF9ED712C5DD1A0 at DEFTHW99EK1MSX dot ww902 dot siemens dot net> <CAM1kHc1wE2xFQD3MSrHi5S5dgqBO0Ji-1av=Z4GFULdLm_siTA at mail dot gmail dot com> <20130422111230 dot GB23625 at xvii dot vinc17 dot org>
> There's the "inexact" exception. But contrary to invalid operations
> (and overflows, at least in rounding to nearest), the only way to
> detect it is to test the exception status flags; the numerical
> value won't say anything about the exception (unless you have some
> knowledge about it, such as you know that the value is an integer
> but you don't get an integer... But not all inexact exceptions can
> be detected in such a way).
Thanks, interesting.
P.S.: Looks like David is right: Doing a runtime conversion raises the
Exception:
#include <stdio.h>
#include <fenv.h>
int main (void) {
volatile int b = 0x7fffffbf;
volatile float c = b;
printf ("inexact = %d\n", fetestexcept (FE_INEXACT));
c /= 123;
printf ("inexact = %d\n", fetestexcept (FE_INEXACT));
return 0;
}
$ ./a.exe
inexact = 32
inexact = 32