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