Blame src/math/lrintf.c

nsz b5bbc6
#include <stdint.h>
nsz b5bbc6
#include <stdio.h>
nsz b5bbc6
#include "util.h"
nsz b5bbc6
nsz b5bbc6
static struct f_i t[] = {
nsz b5bbc6
#include "sanity/lrintf.h"
Szabolcs Nagy f3f0ff
#include "special/lrintf.h"
nsz b5bbc6
nsz b5bbc6
};
nsz b5bbc6
nsz b5bbc6
int main(void)
nsz b5bbc6
{
nsz b5bbc6
	#pragma STDC FENV_ACCESS ON
nsz e08422
	long long yi;
nsz b5bbc6
	int e, i, err = 0;
nsz b5bbc6
	struct f_i *p;
nsz b5bbc6
nsz b5bbc6
	for (i = 0; i < sizeof t/sizeof *t; i++) {
nsz b5bbc6
		p = t + i;
nsz b5bbc6
nsz b5bbc6
		if (p->r < 0)
nsz b5bbc6
			continue;
nsz b5bbc6
		fesetround(p->r);
nsz b5bbc6
		feclearexcept(FE_ALL_EXCEPT);
nsz b5bbc6
		yi = lrintf(p->x);
nsz b5bbc6
		e = fetestexcept(INEXACT|INVALID|DIVBYZERO|UNDERFLOW|OVERFLOW);
nsz b5bbc6
nsz b5bbc6
		if (!checkexcept(e, p->e, p->r)) {
nsz b5bbc6
			printf("%s:%d: bad fp exception: %s lrintf(%a)=%lld, want %s",
nsz b5bbc6
				p->file, p->line, rstr(p->r), p->x, p->i, estr(p->e));
nsz b5bbc6
			printf(" got %s\n", estr(e));
nsz b5bbc6
			err++;
nsz b5bbc6
		}
nsz b5bbc6
		if (yi != p->i) {
nsz e08422
			printf("%s:%d: %s lrintf(%a) want %lld got %lld\n",
nsz b5bbc6
				p->file, p->line, rstr(p->r), p->x, p->i, yi);
nsz b5bbc6
			err++;
nsz b5bbc6
		}
nsz b5bbc6
	}
nsz b5bbc6
	return !!err;
nsz b5bbc6
}