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