math: fix float->int functions
[libc-test] / src / math / gen / template / f_i.c
1 #include <stdint.h>
2 #include <stdio.h>
3 #include "util.h"
4
5 static struct f_i t[] = {
6 HEADERS
7 };
8
9 int main(void)
10 {
11         #pragma STDC FENV_ACCESS ON
12         long long yi;
13         int e, i, err = 0;
14         struct f_i *p;
15
16         for (i = 0; i < sizeof t/sizeof *t; i++) {
17                 p = t + i;
18
19                 if (p->r < 0)
20                         continue;
21                 fesetround(p->r);
22                 feclearexcept(FE_ALL_EXCEPT);
23                 yi = ___(p->x);
24                 e = fetestexcept(INEXACT|INVALID|DIVBYZERO|UNDERFLOW|OVERFLOW);
25
26                 if (!checkexcept(e, p->e, p->r)) {
27                         printf("%s:%d: bad fp exception: %s ___(%a)=%lld, want %s",
28                                 p->file, p->line, rstr(p->r), p->x, p->i, estr(p->e));
29                         printf(" got %s\n", estr(e));
30                         err++;
31                 }
32                 if (yi != p->i) {
33                         printf("%s:%d: %s ___(%a) want %lld got %lld\n",
34                                 p->file, p->line, rstr(p->r), p->x, p->i, yi);
35                         err++;
36                 }
37         }
38         return !!err;
39 }