Blame src/math/jnf.c

nsz 21dd45
#include <stdint.h>
nsz 21dd45
#include <stdio.h>
Szabolcs Nagy cfa23c
#include "mtest.h"
nsz 21dd45
nsz 21dd45
static struct fi_f t[] = {
nsz 21dd45
#include "sanity/jnf.h"
Szabolcs Nagy f3f0ff
#include "special/jnf.h"
nsz 21dd45
};
nsz 21dd45
nsz 21dd45
int main(void)
nsz 21dd45
{
nsz 21dd45
	#pragma STDC FENV_ACCESS ON
nsz 21dd45
	double y;
nsz 21dd45
	float d;
nsz 21dd45
	int e, i, err = 0;
nsz 21dd45
	struct fi_f *p;
nsz 21dd45
nsz 21dd45
	for (i = 0; i < sizeof t/sizeof *t; i++) {
nsz 21dd45
		p = t + i;
nsz 21dd45
nsz 21dd45
		if (p->r < 0)
nsz 21dd45
			continue;
nsz 21dd45
		fesetround(p->r);
nsz 21dd45
		feclearexcept(FE_ALL_EXCEPT);
nsz 21dd45
		y = jnf(p->i, p->x);
nsz 21dd45
		e = fetestexcept(INEXACT|INVALID|DIVBYZERO|UNDERFLOW|OVERFLOW);
nsz 21dd45
nsz 21dd45
		if (!checkexcept(e, p->e, p->r)) {
nsz 21dd45
			printf("%s:%d: bad fp exception: %s jnf(%a, %lld)=%a, want %s",
nsz 21dd45
				p->file, p->line, rstr(p->r), p->x, p->i, p->y, estr(p->e));
nsz 21dd45
			printf(" got %s\n", estr(e));
nsz 21dd45
			err++;
nsz 21dd45
		}
nsz 21dd45
		d = ulperrf(y, p->y, p->dy);
nsz 21dd45
		if (!checkulp(d, p->r)) {
nsz 21dd45
			printf("%s:%d: %s jnf(%a, %lld) want %a got %a, ulperr %.3f = %a + %a\n",
nsz 21dd45
				p->file, p->line, rstr(p->r), p->x, p->i, p->y, y, d, d-p->dy, p->dy);
nsz 21dd45
			err++;
nsz 21dd45
		}
nsz 21dd45
	}
nsz 21dd45
	return !!err;
nsz 21dd45
}