Blame src/math/ynf.c

Szabolcs Nagy 7b5ccd
#define _BSD_SOURCE 1
Szabolcs Nagy 7b5ccd
#define _GNU_SOURCE 1
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/ynf.h"
Szabolcs Nagy f3f0ff
#include "special/ynf.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 = ynf(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 ynf(%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);
Szabolcs Nagy b3580f
		if ((!(p->x < 0) && !checkulp(d, p->r)) || (p->x < 0 && !isnan(y) && y != -inf)) {
nsz 21dd45
			printf("%s:%d: %s ynf(%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
}