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