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