1570af302Sopenharmony_ci#include <stdint.h>
2570af302Sopenharmony_ci#include <stdio.h>
3570af302Sopenharmony_ci#include "mtest.h"
4570af302Sopenharmony_ci
5570af302Sopenharmony_cistatic struct ddd_d t[] = {
6570af302Sopenharmony_ci#include "sanity/fma.h"
7570af302Sopenharmony_ci#include "special/fma.h"
8570af302Sopenharmony_ci};
9570af302Sopenharmony_ci
10570af302Sopenharmony_ciint main(void)
11570af302Sopenharmony_ci{
12570af302Sopenharmony_ci	#pragma STDC FENV_ACCESS ON
13570af302Sopenharmony_ci	double y;
14570af302Sopenharmony_ci	float d;
15570af302Sopenharmony_ci	int e, i, err = 0;
16570af302Sopenharmony_ci	struct ddd_d *p;
17570af302Sopenharmony_ci
18570af302Sopenharmony_ci	for (i = 0; i < sizeof t/sizeof *t; i++) {
19570af302Sopenharmony_ci		p = t + i;
20570af302Sopenharmony_ci
21570af302Sopenharmony_ci		if (p->r < 0)
22570af302Sopenharmony_ci			continue;
23570af302Sopenharmony_ci		fesetround(p->r);
24570af302Sopenharmony_ci		feclearexcept(FE_ALL_EXCEPT);
25570af302Sopenharmony_ci		y = fma(p->x, p->x2, p->x3);
26570af302Sopenharmony_ci		e = fetestexcept(INEXACT|INVALID|DIVBYZERO|UNDERFLOW|OVERFLOW);
27570af302Sopenharmony_ci
28570af302Sopenharmony_ci		/* do not check inexact by default */
29570af302Sopenharmony_ci#if defined CHECK_INEXACT || defined CHECK_INEXACT_OMISSION
30570af302Sopenharmony_ci		if (!checkexceptall(e, p->e, p->r)) {
31570af302Sopenharmony_ci#else
32570af302Sopenharmony_ci		if (!checkexceptall(e|INEXACT, p->e|INEXACT, p->r)) {
33570af302Sopenharmony_ci#endif
34570af302Sopenharmony_ci			printf("%s:%d: bad fp exception: %s fma(%a,%a,%a)=%a, want %s",
35570af302Sopenharmony_ci				p->file, p->line, rstr(p->r), p->x, p->x2, p->x3, p->y, estr(p->e));
36570af302Sopenharmony_ci			printf(" got %s\n", estr(e));
37570af302Sopenharmony_ci			err++;
38570af302Sopenharmony_ci		}
39570af302Sopenharmony_ci		d = ulperr(y, p->y, p->dy);
40570af302Sopenharmony_ci		if (!checkcr(y, p->y, p->r)) {
41570af302Sopenharmony_ci			printf("%s:%d: %s fma(%a,%a,%a) want %a got %a ulperr %.3f = %a + %a\n",
42570af302Sopenharmony_ci				p->file, p->line, rstr(p->r), p->x, p->x2, p->x3, p->y, y, d, d-p->dy, p->dy);
43570af302Sopenharmony_ci			err++;
44570af302Sopenharmony_ci		}
45570af302Sopenharmony_ci	}
46570af302Sopenharmony_ci	return !!err;
47570af302Sopenharmony_ci}
48