-
-static struct {
- int flag;
- char *s;
-} eflags[] = {
- {FE_INVALID, "FE_INVALID"},
- {FE_DIVBYZERO, "FE_DIVBYZERO"},
- {FE_OVERFLOW, "FE_OVERFLOW"},
- {FE_UNDERFLOW, "FE_UNDERFLOW"},
- {FE_INEXACT, "FE_INEXACT"},
-};
-static int ne = sizeof eflags / sizeof *eflags;
-
-static struct {
- int flag;
- char *s;
-} rflags[] = {
- {FE_TONEAREST,"FE_TONEAREST,"},
- {FE_DOWNWARD,"FE_DOWNWARD,"},
- {FE_UPWARD,"FE_UPWARD,"},
- {FE_TOWARDZERO,"FE_TOWARDZERO,"},
-};
-static int nr = sizeof rflags / sizeof *rflags;
-
-void printexcept(int f) {
- int i, all=0;
-
- for (i = 0; i < ne; i++)
- if (f & eflags[i].flag) {
- printf("%s%s", all ? "|" : "", eflags[i].s);
- all |= eflags[i].flag;
- }
- if (all != f) {
- printf("%s%d", all ? "|" : "", f & ~all);
- all = f;
- }
- printf("%s,", all ? "" : "0");
-}
-
-void printround(int f) {
- int i;
-
- for (i = 0; i < nr; i++)
- if (f == rflags[i].flag) {
- printf("%s ", rflags[i].s);
- return;
- }
- printf("%d, ", f);
-}
-
-/*
-struct {double x;} t[] = {
-0.0,
-0.25,
--0.25,
-0.5,
--0.5,
-0.75,
--0.75,
-1.0,
--1.0,
-1.25,
--1.25,
-0x1p30,
--0x1p30,
-0x1p31-1,
--0x1p31+1,
-0x1p31,
--0x1p31,
-0x1p31+1,
--0x1p31-1,
-0x1p31-0.5,
--0x1p31+0.5,
-0x1p31+0.5,
--0x1p31-0.5,
-0x1p32,
--0x1p32,
-0x1p32 - 0.5,
--0x1p32 + 0.5,
-};
-
-void test_gendata()
-{
- int f, i, j;
- long n;
-
- for (i = 0; i < sizeof t/sizeof *t; i++) {
- for (j = 0; j < nr; j++) {
- fesetround(rflags[j].flag);
- feclearexcept(FE_ALL_EXCEPT);
- n = lrint(t[i].x);
- f = fetestexcept(FE_ALL_EXCEPT);
- if (f == FE_INVALID)
- n = 0;
-
- printround(rflags[j].flag);
- printf("%18a, %11ld, ", t[i].x, n);
- printexcept(f);
- printf("\n");
- }
- }
-}
-*/