1 /* Small test program for probing how various math functions
2 * with specific operands set floating point exceptions
5 #define _ISOC99_SOURCE 1
13 int main(int argc
, char **argv
)
15 float largest
, small
, t
, inf_float
;
20 /* optimizations may make plain "t == largest" unreliable */
21 if (memcmp(&t
, &largest
, sizeof(float)) == 0)
30 inf_float
= largest
+ largest
;
31 //printf("%.40g ", largest);
32 //printf("[%llx]\n", (long long) (*(uint32_t *)&largest));
34 feclearexcept(FE_ALL_EXCEPT
);
36 //t = 1.0 / 0.0; // simple test: FE_DIVBYZERO
37 //t = nextafterf(largest, 1); // glibc 2.8: no math exceptions raised
38 //t = nextafterf(largest, largest); // glibc 2.8: no math exceptions raised
39 //t = nextafterf(largest, inf_float); // glibc 2.8: FE_INEXACT FE_OVERFLOW
41 #define PREX(ex) do { if (fetestexcept(ex)) printf(#ex " "); } while(0)
57 if (fetestexcept(FE_ALL_EXCEPT
))
60 printf("no math exceptions raised\n");