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