12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364 |
- #define _ISOC99_SOURCE 1
- #define _GNU_SOURCE 1
- #include <stdint.h>
- #include <math.h>
- #include <fenv.h>
- #include <stdio.h>
- int main(int argc, char **argv)
- {
- float largest, small, t, inf_float;
- largest = small = 1;
- while (1) {
- t = largest + small;
-
- if (memcmp(&t, &largest, sizeof(float)) == 0)
- break;
- if (isfinite(t)) {
- largest = t;
- small *= 2;
- continue;
- }
- small /= 2;
- }
- inf_float = largest + largest;
-
-
- feclearexcept(FE_ALL_EXCEPT);
-
-
-
-
- #define PREX(ex) do { if (fetestexcept(ex)) printf(#ex " "); } while(0)
- #ifdef FE_INEXACT
- PREX(FE_INEXACT);
- #endif
- #ifdef FE_DIVBYZERO
- PREX(FE_DIVBYZERO);
- #endif
- #ifdef FE_UNDERFLOW
- PREX(FE_UNDERFLOW);
- #endif
- #ifdef FE_OVERFLOW
- PREX(FE_OVERFLOW);
- #endif
- #ifdef FE_INVALID
- PREX(FE_INVALID);
- #endif
- if (fetestexcept(FE_ALL_EXCEPT))
- printf("\n");
- else
- printf("no math exceptions raised\n");
- printf("%.40g\n", t);
- return 0;
- }
|