Blame src/math/lround.c

nsz b5bbc6
#include <stdint.h>
nsz b5bbc6
#include <stdio.h>
nsz b5bbc6
#include "util.h"
nsz b5bbc6
nsz b5bbc6
static struct d_i t[] = {
nsz b5bbc6
#include "sanity/lround.h"
Szabolcs Nagy f3f0ff
#include "special/lround.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 d_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 = lround(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 lround(%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
		}
Szabolcs Nagy b3580f
		if (!(p->e&INVALID) && yi != p->i) {
nsz e08422
			printf("%s:%d: %s lround(%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
}