RE: float to int conversion

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



> 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 of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux