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