This is the mail archive of the gcc-help@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

RE: float to int conversion


> 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

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]