fnmatch: fix "[/b" test
[libc-test] / src / math / sanity.c
1 #include <stdio.h>
2 #include <math.h>
3 #include "test.h"
4
5 static int check(double a, double b)
6 {
7         double d = a - b;
8         return fabs(d) <= 0x1p-52*fabs(a);
9 }
10
11 static int checkf(float a, float b)
12 {
13         float d = a - b;
14         return fabsf(d) <= 0x1p-23*fabsf(a);
15 }
16
17 static int checkl(long double a, long double b)
18 {
19         long double d = a - b;
20         return fabsl(d) <= 0x1p-63L*fabsl(a);
21 }
22
23 #define D(fx, y) do{ \
24         volatile double yy = fx; \
25         volatile long double yl = fx; \
26         if (!check(yy, y)) \
27                 error("%s got %a = %.21e want %a = %.21e\n", #fx, yy, yy, y, y); \
28         if (yy != yl) \
29                 error("float-store issue: (double)%s = %a (long double)%s = %La\n", #fx, yy, #fx, yl); \
30 }while(0)
31
32 #define F(fx, y) do{ \
33         volatile float yy = fx; \
34         volatile long double yl = fx; \
35         if (!checkf(yy, y)) \
36                 error("%s got %a = %.21e want %a = %.21e\n", #fx, yy, yy, y, y); \
37         if (yy != yl) \
38                 error("float-store issue: (float)%s = %a (long double)%s = %La\n", #fx, yy, #fx, yl); \
39 }while(0)
40
41 #define L(fx, y) do{ \
42         long double yy = fx; \
43         if (!checkl(yy, y)) \
44                 error("%s got %La = %.21Le want %La = %.21Le\n", #fx, yy, yy, y, y); \
45 }while(0)
46
47 #define I(fx, y) do{ \
48         int yy = fx; \
49         if (yy != y) \
50                 error("%s got %d want %d\n", #fx, yy, y); \
51 }while(0)
52
53 #define IL(fx, y) do{ \
54         long yy = fx; \
55         if (yy != y) \
56                 error("%s got %ld want %ld\n", #fx, yy, y); \
57 }while(0)
58
59 #define ILL(fx, y) do{ \
60         long long yy = fx; \
61         if (yy != y) \
62                 error("%s got %lld want %lld\n", #fx, yy, y); \
63 }while(0)
64
65 void test_math_sanity()
66 {
67         int i;
68         double q;
69         float qf;
70         long double ql;
71
72 D(acos(0.7), 0x1.973e83f5d5c9bp-1);
73 F(acosf(0.7f), 0x1.973e84p-1);
74 L(acosl(0.7L), 0x1.973e83f5d5c9aaf8p-1L);
75 D(acosh(1.7), 0x1.1f8c10d010fe6p+0);
76 F(acoshf(1.7f), 0x1.1f8c12p+0);
77 L(acoshl(1.7L), 0x1.1f8c10d010fe5d96p+0L);
78 D(asin(0.7), 0x1.8d00e692afd95p-1);
79 F(asinf(0.7f), 0x1.8d00e6p-1);
80 L(asinl(0.7L), 0x1.8d00e692afd95ddap-1L);
81 D(asinh(0.7), 0x1.4e2a4fe9085ddp-1);
82 F(asinhf(0.7f), 0x1.4e2a5p-1);
83 L(asinhl(0.7L), 0x1.4e2a4fe9085dd732p-1L);
84 D(atan(0.7), 0x1.38b112d7bd4adp-1);
85 F(atanf(0.7f), 0x1.38b112p-1);
86 L(atanl(0.7L), 0x1.38b112d7bd4ad786p-1L);
87 D(atan2(0.7, 1.0), 0x1.38b112d7bd4adp-1);
88 F(atan2f(0.7f, 1.0f), 0x1.38b112p-1);
89 L(atan2l(0.7L, 1.0L), 0x1.38b112d7bd4ad786p-1L);
90 D(atanh(0.7), 0x1.bc0ed0947fbe8p-1);
91 F(atanhf(0.7f), 0x1.bc0edp-1);
92 L(atanhl(0.7L), 0x1.bc0ed0947fbe9068p-1L);
93 D(cbrt(0.7), 0x1.c69b5a72f1a99p-1);
94 F(cbrtf(0.7f), 0x1.c69b5ap-1);
95 L(cbrtl(0.7L), 0x1.c69b5a72f1a99902p-1L);
96 D(ceil(0.7), 0x1p+0);
97 F(ceilf(0.7f), 0x1p+0);
98 L(ceill(0.7L), 0x1p+0L);
99 D(copysign(0.7, -1.0), -0x1.6666666666666p-1);
100 F(copysignf(0.7f, -1.0f), -0x1.666666p-1);
101 L(copysignl(0.7L, -1.0L), -0x1.6666666666666666p-1L);
102 D(cos(0.7), 0x1.87996529f9d93p-1);
103 F(cosf(0.7f), 0x1.879966p-1);
104 L(cosl(0.7L), 0x1.87996529f9d92618p-1L);
105 D(cosh(0.7), 0x1.4152c1862342fp+0);
106 F(coshf(0.7f), 0x1.4152c2p+0);
107 L(coshl(0.7L), 0x1.4152c1862342ef8ep+0L);
108 D(erf(0.7), 0x1.5b08c21171646p-1);
109 F(erff(0.7f), 0x1.5b08c2p-1);
110 L(erfl(0.7L), 0x1.5b08c21171646544p-1L);
111 D(erfc(0.7), 0x1.49ee7bdd1d374p-2);
112 F(erfcf(0.7f), 0x1.49ee7cp-2);
113 L(erfcl(0.7L), 0x1.49ee7bdd1d373576p-2L);
114 D(exp(0.7), 0x1.01c2a61268987p+1);
115 F(expf(0.7f), 0x1.01c2a6p+1);
116 L(expl(0.7L), 0x1.01c2a61268986bfep+1L);
117 D(exp2(0.7), 0x1.9fdf8bcce533dp+0);
118 F(exp2f(0.7f), 0x1.9fdf8cp+0);
119 L(exp2l(0.7L), 0x1.9fdf8bcce533d72p+0L);
120 D(expm1(0.7), 0x1.03854c24d130dp+0);
121 F(expm1f(0.7f), 0x1.03854cp+0);
122 L(expm1l(0.7L), 0x1.03854c24d130d7fep+0L);
123 D(fabs(-0.7), 0x1.6666666666666p-1);
124 F(fabsf(-0.7f), 0x1.666666p-1);
125 L(fabsl(-0.7L), 0x1.6666666666666666p-1L);
126 D(fdim(0.7, 0.5), 0x1.9999999999998p-3);
127 F(fdimf(0.7f, 0.5f), 0x1.999998p-3);
128 L(fdiml(0.7L, 0.5L), 0x1.9999999999999998p-3L);
129 D(floor(0.7), 0x0p+0);
130 F(floorf(0.7f), 0x0p+0);
131 L(floorl(0.7L), 0x0p+0L);
132 D(fma(0.7, 2.0, 0.1), 0x1.8p+0);
133 F(fmaf(0.7f, 2.0f, 0.1f), 0x1.8p+0);
134 L(fmal(0.7L, 2.0L, 0.1L), 0x1.8p+0L);
135 D(fmax(0.7, 0.5), 0x1.6666666666666p-1);
136 F(fmaxf(0.7f, 0.5), 0x1.666666p-1);
137 L(fmaxl(0.7L, 0.5), 0x1.6666666666666666p-1L);
138 D(fmin(0.7, 0.5), 0x1p-1);
139 F(fminf(0.7f, 0.5f), 0x1p-1);
140 L(fminl(0.7L, 0.5L), 0x1p-1L);
141 D(fmod(0.7, 0.5), 0x1.9999999999998p-3);
142 F(fmodf(0.7f, 0.5f), 0x1.999998p-3);
143 L(fmodl(0.7L, 0.5L), 0x1.9999999999999998p-3L);
144 D(frexp(0.7, &i), 0x1.6666666666666p-1);
145 F(frexpf(0.7f, &i), 0x1.666666p-1);
146 L(frexpl(0.7L, &i), 0x1.6666666666666666p-1L);
147 D(hypot(0.7, 1.0), 0x1.387ce204a35d2p+0);
148 F(hypotf(0.7f, 1.0f), 0x1.387ce2p+0);
149 L(hypotl(0.7L, 1.0L), 0x1.387ce204a35d1ff6p+0L);
150 I(ilogb(0.7), -1);
151 I(ilogbf(0.7f), -1);
152 I(ilogbl(0.7L), -1);
153 D(j0(0.7), 0x1.c32cc34b8cc59p-1);
154 F(j0f(0.7f), 0x1.c32cc4p-1);
155 D(j1(0.7), 0x1.50e44279c0546p-2);
156 F(j1f(0.7f), 0x1.50e442p-2);
157 D(jn(2, 0.7), 0x1.e195286f3b2fbp-5);
158 F(jnf(2, 0.7f), 0x1.e19528p-5);
159 D(ldexp(0.7, 3), 0x1.6666666666666p+2);
160 F(ldexpf(0.7f, 3), 0x1.666666p+2);
161 L(ldexpl(0.7L, 3), 0x1.6666666666666666p+2L);
162 D(lgamma(0.7), 0x1.0b20c891cde73p-2);
163 F(lgammaf(0.7f), 0x1.0b20cap-2);
164 L(lgammal(0.7L), 0x1.0b20c891cde72846p-2L);
165 D(lgamma_r(0.7, &i), 0x1.0b20c891cde73p-2);
166 F(lgammaf_r(0.7f, &i), 0x1.0b20cap-2);
167 L(lgammal_r(0.7L, &i), 0x1.0b20c891cde72846p-2L);
168 ILL(llrint(0.7), 1);
169 ILL(llrintf(0.7f), 1);
170 ILL(llrintl(0.7l), 1);
171 ILL(llround(0.7), 1);
172 ILL(llroundf(0.7f), 1);
173 ILL(llroundl(0.7L), 1);
174 D(log(0.7), -0x1.6d3c324e13f5p-2);
175 F(logf(0.7f), -0x1.6d3c34p-2);
176 L(logl(0.7L), -0x1.6d3c324e13f4ec54p-2L);
177 D(log10(0.7), -0x1.3d3d3d21ccf04p-3);
178 F(log10f(0.7f), -0x1.3d3d3ep-3);
179 L(log10l(0.7L), -0x1.3d3d3d21ccf035a6p-3L);
180 D(log1p(0.7), 0x1.0fae81914a991p-1);
181 F(log1pf(0.7f), 0x1.0fae82p-1);
182 L(log1pl(0.7L), 0x1.0fae81914a991308p-1L);
183 D(log2(0.7), -0x1.0776228967d13p-1);
184 F(log2f(0.7f), -0x1.077624p-1);
185 L(log2l(0.7L), -0x1.0776228967d1218cp-1L);
186 D(logb(0.7), -0x1p+0);
187 F(logbf(0.7f), -0x1p+0);
188 L(logbl(0.7L), -0x1p+0L);
189 IL(lrint(0.7), 1);
190 IL(lrintf(0.7f), 1);
191 IL(lrintl(0.7l), 1);
192 IL(lround(0.7), 1);
193 IL(lroundf(0.7f), 1);
194 IL(lroundl(0.7L), 1);
195 D(modf(0.7, &q), 0x1.6666666666666p-1);
196 F(modff(0.7f, &qf), 0x1.666666p-1);
197 L(modfl(0.7L, &ql), 0x1.6666666666666666p-1L);
198 D(nearbyint(0.7), 0x1p+0);
199 F(nearbyintf(0.7f), 0x1p+0);
200 L(nearbyintl(0.7L), 0x1p+0L);
201 D(nextafter(0.7, 1.0), 0x1.6666666666667p-1);
202 F(nextafterf(0.7f, 1.0f), 0x1.666668p-1);
203 L(nextafterl(0.7L, 1.0L), 0x1.6666666666666667p-1L);
204 D(nexttoward(0.7, 1.0L), 0x1.6666666666667p-1);
205 F(nexttowardf(0.7f, 1.0L), 0x1.666668p-1);
206 L(nexttowardl(0.7L, 1.0L), 0x1.6666666666666667p-1L);
207 D(pow(0.7, 1.5), 0x1.2bdbe460916ep-1);
208 F(powf(0.7f, 1.5f), 0x1.2bdbe4p-1);
209 L(powl(0.7L, 1.5L), 0x1.2bdbe460916e0b5p-1L);
210 D(remainder(0.7, 0.5), 0x1.9999999999998p-3);
211 F(remainderf(0.7f, 0.5f), 0x1.999998p-3);
212 L(remainderl(0.7L, 0.5L), 0x1.9999999999999998p-3L);
213 D(remquo(0.7, 0.5, &i), 0x1.9999999999998p-3);
214 F(remquof(0.7f, 0.5f, &i), 0x1.999998p-3);
215 L(remquol(0.7L, 0.5L, &i), 0x1.9999999999999998p-3L);
216 D(rint(0.7), 0x1p+0);
217 F(rintf(0.7f), 0x1p+0);
218 L(rintl(0.7L), 0x1p+0L);
219 D(round(0.7), 0x1p+0);
220 F(roundf(0.7f), 0x1p+0);
221 L(roundl(0.7L), 0x1p+0L);
222 D(scalb(0.7, 3), 0x1.6666666666666p+2);
223 F(scalbf(0.7f, 3), 0x1.666666p+2);
224 D(scalbln(0.7, 3), 0x1.6666666666666p+2);
225 F(scalblnf(0.7f, 3), 0x1.666666p+2);
226 L(scalblnl(0.7L, 3), 0x1.6666666666666666p+2L);
227 D(scalbn(0.7, 3), 0x1.6666666666666p+2);
228 F(scalbnf(0.7f, 3), 0x1.666666p+2);
229 L(scalbnl(0.7L, 3), 0x1.6666666666666666p+2L);
230 D(sin(0.7), 0x1.49d6e694619b8p-1);
231 F(sinf(0.7f), 0x1.49d6e6p-1);
232 L(sinl(0.7L), 0x1.49d6e694619b854ep-1L);
233 D(sinh(0.7), 0x1.8465153d5bdbdp-1);
234 F(sinhf(0.7f), 0x1.846514p-1);
235 L(sinhl(0.7L), 0x1.8465153d5bdbd0dep-1L);
236 D(sqrt(0.7), 0x1.ac5eb3f7ab2f8p-1);
237 F(sqrtf(0.7f), 0x1.ac5eb4p-1);
238 L(sqrtl(0.7L), 0x1.ac5eb3f7ab2f7de2p-1L);
239 D(tan(0.7), 0x1.af406c2fc78aep-1);
240 F(tanf(0.7f), 0x1.af406cp-1);
241 L(tanl(0.7L), 0x1.af406c2fc78ae54cp-1L);
242 D(tanh(0.7), 0x1.356fb17af2e91p-1);
243 F(tanhf(0.7f), 0x1.356fb2p-1);
244 L(tanhl(0.7L), 0x1.356fb17af2e9100ap-1L);
245 D(tgamma(0.7), 0x1.4c4d5ab21ea23p+0);
246 F(tgammaf(0.7f), 0x1.4c4d5cp+0);
247 L(tgammal(0.7L), 0x1.4c4d5ab21ea22798p+0L);
248 D(trunc(0.7), 0x0p+0);
249 F(truncf(0.7f), 0x0p+0);
250 L(truncl(0.7L), 0x0p+0L);
251 D(y0(0.7), -0x1.867b559ffc715p-3);
252 F(y0f(0.7f), -0x1.867b58p-3);
253 D(y1(0.7), -0x1.1a6e956728d35p+0);
254 F(y1f(0.7f), -0x1.1a6e96p+0);
255 D(yn(2, 0.7), -0x1.7b11b25df166ep+1);
256 F(ynf(2, 0.7f), -0x1.7b11b4p+1);
257 }