xref: /third_party/musl/libc-test/src/math/remquol.c (revision 570af302)
1#include <stdint.h>
2#include <stdio.h>
3#include "mtest.h"
4
5static struct ll_li t[] = {
6#if LDBL_MANT_DIG == 53
7#include "sanity/remquo.h"
8#include "special/remquo.h"
9
10#elif LDBL_MANT_DIG == 64
11#include "sanity/remquol.h"
12#include "special/remquol.h"
13
14#endif
15};
16
17int main(void)
18{
19	#pragma STDC FENV_ACCESS ON
20	int yi;
21	long double y;
22	float d;
23	int e, i, err = 0;
24	struct ll_li *p;
25
26	for (i = 0; i < sizeof t/sizeof *t; i++) {
27		p = t + i;
28
29		if (p->r < 0)
30			continue;
31		fesetround(p->r);
32		feclearexcept(FE_ALL_EXCEPT);
33		y = remquol(p->x, p->x2, &yi);
34		e = fetestexcept(INEXACT|INVALID|DIVBYZERO|UNDERFLOW|OVERFLOW);
35
36		if (!checkexcept(e, p->e, p->r)) {
37			printf("%s:%d: bad fp exception: %s remquol(%La,%La)=%La,%lld, want %s",
38				p->file, p->line, rstr(p->r), p->x, p->x2, p->y, p->i, estr(p->e));
39			printf(" got %s\n", estr(e));
40			err++;
41		}
42		d = ulperr(y, p->y, p->dy);
43		if (!checkcr(y, p->y, p->r) ||
44		(!isnan(p->y) && (yi & 7) != (p->i & 7)) ||
45		(!isnan(p->y) && (yi < 0) != (p->i < 0))) {
46			printf("%s:%d: %s remquol(%La,%La) want %La,%lld got %La,%d ulperr %.3f = %a + %a\n",
47				p->file, p->line, rstr(p->r), p->x, p->x2, p->y, p->i, y, yi, d, d-p->dy, p->dy);
48			err++;
49		}
50	}
51	return !!err;
52}
53