xref: /third_party/musl/libc-test/src/math/sincosl.c (revision 570af302)
1570af302Sopenharmony_ci#define _GNU_SOURCE 1
2570af302Sopenharmony_ci#include <stdint.h>
3570af302Sopenharmony_ci#include <stdio.h>
4570af302Sopenharmony_ci#include "mtest.h"
5570af302Sopenharmony_ci
6570af302Sopenharmony_cistatic struct l_ll t[] = {
7570af302Sopenharmony_ci#if LDBL_MANT_DIG == 53
8570af302Sopenharmony_ci#include "sanity/sincos.h"
9570af302Sopenharmony_ci#include "special/sincos.h"
10570af302Sopenharmony_ci#elif LDBL_MANT_DIG == 64
11570af302Sopenharmony_ci#include "sanity/sincosl.h"
12570af302Sopenharmony_ci#include "special/sincosl.h"
13570af302Sopenharmony_ci#endif
14570af302Sopenharmony_ci};
15570af302Sopenharmony_ci
16570af302Sopenharmony_ciint main(void)
17570af302Sopenharmony_ci{
18570af302Sopenharmony_ci	#pragma STDC FENV_ACCESS ON
19570af302Sopenharmony_ci	long double ysin, ycos;
20570af302Sopenharmony_ci	float dsin, dcos;
21570af302Sopenharmony_ci	int e, i, err = 0;
22570af302Sopenharmony_ci	struct l_ll *p;
23570af302Sopenharmony_ci
24570af302Sopenharmony_ci	for (i = 0; i < sizeof t/sizeof *t; i++) {
25570af302Sopenharmony_ci		p = t + i;
26570af302Sopenharmony_ci
27570af302Sopenharmony_ci		if (p->r < 0)
28570af302Sopenharmony_ci			continue;
29570af302Sopenharmony_ci		fesetround(p->r);
30570af302Sopenharmony_ci		feclearexcept(FE_ALL_EXCEPT);
31570af302Sopenharmony_ci		sincosl(p->x, &ysin, &ycos);
32570af302Sopenharmony_ci		e = fetestexcept(INEXACT|INVALID|DIVBYZERO|UNDERFLOW|OVERFLOW);
33570af302Sopenharmony_ci
34570af302Sopenharmony_ci		if (!checkexcept(e, p->e, p->r)) {
35570af302Sopenharmony_ci			printf("%s:%d: bad fp exception: %s sincosl(%La)=%La,%La, want %s",
36570af302Sopenharmony_ci				p->file, p->line, rstr(p->r), p->x, p->y, p->y2, estr(p->e));
37570af302Sopenharmony_ci			printf(" got %s\n", estr(e));
38570af302Sopenharmony_ci			err++;
39570af302Sopenharmony_ci		}
40570af302Sopenharmony_ci		dsin = ulperr(ysin, p->y, p->dy);
41570af302Sopenharmony_ci		dcos = ulperr(ycos, p->y2, p->dy2);
42570af302Sopenharmony_ci		if (!checkulp(dsin, p->r) || !checkulp(dcos, p->r)) {
43570af302Sopenharmony_ci			printf("%s:%d: %s sincosl(%La) want %La,%La got %La,%La, ulperr %.3f = %a + %a, %.3f = %a + %a\n",
44570af302Sopenharmony_ci				p->file, p->line, rstr(p->r), p->x, p->y, p->y2, ysin, ycos,
45570af302Sopenharmony_ci				dsin, dsin-p->dy, p->dy, dcos, dcos-p->dy2, p->dy2);
46570af302Sopenharmony_ci			err++;
47570af302Sopenharmony_ci		}
48570af302Sopenharmony_ci	}
49570af302Sopenharmony_ci	return !!err;
50570af302Sopenharmony_ci}
51