math += nextafter, nextafterl tests
[libc-test] / src / math / fenvutil.c
1 #include <fenv.h>
2 #include <stdio.h>
3 #include "fenvutil.h"
4
5 static struct {
6         int flag;
7         char *s;
8 } eflags[] = {
9         {FE_INVALID, "FE_INVALID"},
10         {FE_DIVBYZERO, "FE_DIVBYZERO"},
11         {FE_OVERFLOW, "FE_OVERFLOW"},
12         {FE_UNDERFLOW, "FE_UNDERFLOW"},
13         {FE_INEXACT, "FE_INEXACT"},
14 };
15 static int ne = sizeof eflags / sizeof *eflags;
16
17 static struct {
18         int flag;
19         char *s;
20 } rflags[] = {
21         {FE_TONEAREST,"FE_TONEAREST"},
22         {FE_DOWNWARD,"FE_DOWNWARD"},
23         {FE_UPWARD,"FE_UPWARD"},
24         {FE_TOWARDZERO,"FE_TOWARDZERO"},
25 };
26 static int nr = sizeof rflags / sizeof *rflags;
27
28 char *strexcept(int f) {
29         static char buf[256];
30         char *p;
31         int i, all=0;
32
33         p = buf;
34         for (i = 0; i < ne; i++)
35                 if (f & eflags[i].flag) {
36                         p += sprintf(p, "%s%s", all ? "|" : "", eflags[i].s);
37                         all |= eflags[i].flag;
38                 }
39         if (all != f) {
40                 p += sprintf(p, "%s%d", all ? "|" : "", f & ~all);
41                 all = f;
42         }
43         p += sprintf(p, "%s", all ? "" : "0");
44         return buf;
45 }
46
47 char *strround(int f) {
48         static char buf[256];
49         int i;
50
51         for (i = 0; i < nr; i++)
52                 if (f == rflags[i].flag) {
53                         sprintf(buf, "%s", rflags[i].s);
54                         return buf;
55                 }
56         sprintf(buf, "%d", f);
57         return buf;
58 }
59