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