Blame src/math/modff.c

nsz cb9f87
#include <stdint.h>
nsz cb9f87
#include <stdio.h>
Szabolcs Nagy cfa23c
#include "mtest.h"
nsz cb9f87
nsz cb9f87
static struct f_ff t[] = {
nsz cb9f87
#include "sanity/modff.h"
Szabolcs Nagy f3f0ff
#include "special/modff.h"
nsz cb9f87
};
nsz cb9f87
nsz cb9f87
int main(void)
nsz cb9f87
{
nsz cb9f87
	#pragma STDC FENV_ACCESS ON
nsz cb9f87
	float y, yi;
nsz cb9f87
	float d, di;
nsz cb9f87
	int e, i, err = 0;
nsz cb9f87
	struct f_ff *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 = modff(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 modff(%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);
Szabolcs Nagy 9c6efc
		if (!checkcr(y, p->y, p->r) || !checkcr(yi, p->y2, p->r)) {
nsz cb9f87
			printf("%s:%d: %s modff(%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
}