1570af302Sopenharmony_ci#define _DEFAULT_SOURCE 1
2570af302Sopenharmony_ci#define _BSD_SOURCE 1
3570af302Sopenharmony_ci#include <stdint.h>
4570af302Sopenharmony_ci#include <stdio.h>
5570af302Sopenharmony_ci#include "mtest.h"
6570af302Sopenharmony_ci
7570af302Sopenharmony_cistatic struct f_f t[] = {
8570af302Sopenharmony_ci#include "sanity/y0f.h"
9570af302Sopenharmony_ci#include "special/y0f.h"
10570af302Sopenharmony_ci
11570af302Sopenharmony_ci};
12570af302Sopenharmony_ci
13570af302Sopenharmony_ciint main(void)
14570af302Sopenharmony_ci{
15570af302Sopenharmony_ci	#pragma STDC FENV_ACCESS ON
16570af302Sopenharmony_ci	float y;
17570af302Sopenharmony_ci	float d;
18570af302Sopenharmony_ci	int e, i, bad, err = 0;
19570af302Sopenharmony_ci	struct f_f *p;
20570af302Sopenharmony_ci
21570af302Sopenharmony_ci	for (i = 0; i < sizeof t/sizeof *t; i++) {
22570af302Sopenharmony_ci		p = t + i;
23570af302Sopenharmony_ci
24570af302Sopenharmony_ci		if (p->r < 0)
25570af302Sopenharmony_ci			continue;
26570af302Sopenharmony_ci		fesetround(p->r);
27570af302Sopenharmony_ci		feclearexcept(FE_ALL_EXCEPT);
28570af302Sopenharmony_ci		y = y0f(p->x);
29570af302Sopenharmony_ci		e = fetestexcept(INEXACT|INVALID|DIVBYZERO|UNDERFLOW|OVERFLOW);
30570af302Sopenharmony_ci
31570af302Sopenharmony_ci#ifndef __aarch64__
32570af302Sopenharmony_ci		if (!checkexcept(e, p->e, p->r)) {
33570af302Sopenharmony_ci			printf("%s:%d: bad fp exception: %s y0f(%a)=%a, want %s",
34570af302Sopenharmony_ci				p->file, p->line, rstr(p->r), p->x, p->y, estr(p->e));
35570af302Sopenharmony_ci			printf(" got %s\n", estr(e));
36570af302Sopenharmony_ci			err++;
37570af302Sopenharmony_ci		}
38570af302Sopenharmony_ci#endif
39570af302Sopenharmony_ci		d = ulperrf(y, p->y, p->dy);
40570af302Sopenharmony_ci		bad = p->x < 0 && !isnan(y) && y != -inf;
41570af302Sopenharmony_ci		if (bad || (!(p->x < 0) && !checkulp(d, p->r))) {
42570af302Sopenharmony_ci			if (!bad && fabsf(d) < 0x1p23f)
43570af302Sopenharmony_ci				printf("X ");
44570af302Sopenharmony_ci			else
45570af302Sopenharmony_ci				err++;
46570af302Sopenharmony_ci			printf("%s:%d: %s y0f(%a) want %a got %a ulperr %.3f = %a + %a\n",
47570af302Sopenharmony_ci				p->file, p->line, rstr(p->r), p->x, p->y, y, d, d-p->dy, p->dy);
48570af302Sopenharmony_ci		}
49570af302Sopenharmony_ci	}
50570af302Sopenharmony_ci	return !!err;
51570af302Sopenharmony_ci}
52