|
nsz |
ddfb9f |
#include <stdint.h>
|
|
nsz |
ddfb9f |
#include <stdio.h>
|
|
nsz |
ddfb9f |
#include "util.h"
|
|
nsz |
ddfb9f |
|
|
nsz |
ddfb9f |
static struct ll_l t[] = {
|
|
nsz |
ddfb9f |
#if LDBL_MANT_DIG == 53
|
|
nsz |
ddfb9f |
#include "sanity/nexttowardf.h"
|
|
nsz |
ddfb9f |
|
|
nsz |
ddfb9f |
#elif LDBL_MANT_DIG == 64
|
|
nsz |
ddfb9f |
#include "sanity/nexttowardf.h"
|
|
nsz |
ddfb9f |
|
|
nsz |
ddfb9f |
#endif
|
|
nsz |
ddfb9f |
};
|
|
nsz |
ddfb9f |
|
|
nsz |
ddfb9f |
int main(void)
|
|
nsz |
ddfb9f |
{
|
|
nsz |
ddfb9f |
#pragma STDC FENV_ACCESS ON
|
|
nsz |
ddfb9f |
long double y;
|
|
nsz |
ddfb9f |
float d;
|
|
nsz |
ddfb9f |
int e, i, err = 0;
|
|
nsz |
ddfb9f |
struct ll_l *p;
|
|
nsz |
ddfb9f |
|
|
nsz |
ddfb9f |
for (i = 0; i < sizeof t/sizeof *t; i++) {
|
|
nsz |
ddfb9f |
p = t + i;
|
|
nsz |
ddfb9f |
|
|
nsz |
ddfb9f |
if (p->r < 0)
|
|
nsz |
ddfb9f |
continue;
|
|
nsz |
ddfb9f |
fesetround(p->r);
|
|
nsz |
ddfb9f |
feclearexcept(FE_ALL_EXCEPT);
|
|
nsz |
ddfb9f |
y = nexttowardf(p->x, p->x2);
|
|
nsz |
ddfb9f |
e = fetestexcept(INEXACT|INVALID|DIVBYZERO|UNDERFLOW|OVERFLOW);
|
|
nsz |
ddfb9f |
|
|
nsz |
ddfb9f |
if (!checkexcept(e, p->e, p->r)) {
|
|
nsz |
ddfb9f |
printf("%s:%d: bad fp exception: %s nexttowardf(%La,%La)=%La, want %s",
|
|
nsz |
ddfb9f |
p->file, p->line, rstr(p->r), p->x, p->x2, p->y, estr(p->e));
|
|
nsz |
ddfb9f |
printf(" got %s\n", estr(e));
|
|
nsz |
ddfb9f |
err++;
|
|
nsz |
ddfb9f |
}
|
|
nsz |
ddfb9f |
d = ulperrl(y, p->y, p->dy);
|
|
nsz |
ddfb9f |
if (!checkulp(d, p->r)) {
|
|
nsz |
ddfb9f |
printf("%s:%d: %s nexttowardf(%La,%La) want %La got %La ulperr %.3f = %a + %a\n",
|
|
nsz |
ddfb9f |
p->file, p->line, rstr(p->r), p->x, p->x2, p->y, y, d, d-p->dy, p->dy);
|
|
nsz |
ddfb9f |
err++;
|
|
nsz |
ddfb9f |
}
|
|
nsz |
ddfb9f |
}
|
|
nsz |
ddfb9f |
return !!err;
|
|
nsz |
ddfb9f |
}
|