test: sync tst-atfork2 with GNU libc
[uclibc-ng.git] / libm / float_wrappers.c
blob105486e468836ce4bd60e552b247a148a85edb0a
1 /* vi: set sw=4 ts=4: */
2 /*
3 * Wrapper functions implementing all the float math functions
4 * defined by SuSv3 by actually calling the double version of
5 * each function and then casting the result back to a float
6 * to return to the user.
8 * Copyright (C) 2005 by Erik Andersen <andersen@uclibc.org>
10 * GNU Lesser General Public License version 2.1 or later.
13 #include <features.h>
14 /* Prevent math.h from defining colliding inlines */
15 #undef __USE_EXTERN_INLINES
16 #include <math.h>
17 #include <complex.h>
20 #define WRAPPER1(func) \
21 float func##f (float x) \
22 { \
23 return (float) func((double)x); \
25 #define int_WRAPPER1(func) \
26 int func##f (float x) \
27 { \
28 return func((double)x); \
30 #define long_WRAPPER1(func) \
31 long func##f (float x) \
32 { \
33 return func((double)x); \
35 #define long_long_WRAPPER1(func) \
36 long long func##f (float x) \
37 { \
38 return func((double)x); \
41 #ifndef __DO_XSI_MATH__
42 # undef L_j0f /* float j0f(float x); */
43 # undef L_j1f /* float j1f(float x); */
44 # undef L_jnf /* float jnf(int n, float x); */
45 # undef L_y0f /* float y0f(float x); */
46 # undef L_y1f /* float y1f(float x); */
47 # undef L_ynf /* float ynf(int n, float x); */
48 #endif
50 /* Implement the following, as defined by SuSv3 */
51 #if 0
52 float acosf(float);
53 float acoshf(float);
54 float asinf(float);
55 float asinhf(float);
56 float atan2f(float, float);
57 float atanf(float);
58 float atanhf(float);
59 float cargf(float complex);
60 float cbrtf(float);
61 float ceilf(float);
62 float copysignf(float, float);
63 float cosf(float);
64 float coshf(float);
65 float erfcf(float);
66 float erff(float);
67 float exp2f(float);
68 float expf(float);
69 float expm1f(float);
70 float fabsf(float);
71 float floorf(float);
72 float fmodf(float, float);
73 float frexpf(float value, int *);
74 float hypotf(float, float);
75 int ilogbf(float);
76 float ldexpf(float, int);
77 float lgammaf(float);
78 long long llroundf(float);
79 float log10f(float);
80 float log1pf(float);
81 float log2f(float);
82 float logbf(float);
83 float logf(float);
84 long lroundf(float);
85 float modff(float, float *);
86 float powf(float, float);
87 float remainderf(float, float);
88 float rintf(float);
89 float roundf(float);
90 float scalbnf(float, int);
91 float sinf(float);
92 float sinhf(float);
93 float sqrtf(float);
94 float tanf(float);
95 float tanhf(float);
96 #endif
98 #ifdef L_acosf
99 WRAPPER1(acos)
100 #endif
102 #ifdef L_acoshf
103 WRAPPER1(acosh)
104 #endif
106 #ifdef L_asinf
107 WRAPPER1(asin)
108 #endif
110 #ifdef L_asinhf
111 WRAPPER1(asinh)
112 #endif
114 #ifdef L_atan2f
115 float atan2f (float x, float y)
117 return (float) atan2( (double)x, (double)y );
119 #endif
121 #ifdef L_atanf
122 WRAPPER1(atan)
123 #endif
125 #ifdef L_atanhf
126 WRAPPER1(atanh)
127 #endif
129 #ifdef L_cargf
130 float cargf (float complex x)
132 return (float) carg( (double complex)x );
134 #endif
136 #ifdef L_cbrtf
137 WRAPPER1(cbrt)
138 #endif
140 #ifdef L_ceilf
141 WRAPPER1(ceil)
142 #endif
144 #ifdef L_copysignf
145 float copysignf (float x, float y)
147 return (float) copysign( (double)x, (double)y );
149 #endif
151 #ifdef L_cosf
152 WRAPPER1(cos)
153 libm_hidden_def(cosf)
154 #endif
156 #ifdef L_coshf
157 WRAPPER1(cosh)
158 #endif
160 #ifdef L_erfcf
161 WRAPPER1(erfc)
162 #endif
164 #ifdef L_erff
165 WRAPPER1(erf)
166 #endif
168 #ifdef L_exp2f
169 WRAPPER1(exp2)
170 #endif
172 #ifdef L_expf
173 WRAPPER1(exp)
174 #endif
176 #ifdef L_expm1f
177 WRAPPER1(expm1)
178 #endif
180 #ifdef L_fabsf
181 WRAPPER1(fabs)
182 #endif
184 #ifdef L_fdimf
185 float fdimf (float x, float y)
187 return (float) fdim( (double)x, (double)y );
189 #endif
191 #ifdef L_floorf
192 WRAPPER1(floor)
193 #endif
195 #ifdef L_fmaf
196 float fmaf (float x, float y, float z)
198 return (float) fma( (double)x, (double)y, (double)z );
200 #endif
202 #ifdef L_fmaxf
203 float fmaxf (float x, float y)
205 return (float) fmax( (double)x, (double)y );
207 #endif
209 #ifdef L_fminf
210 float fminf (float x, float y)
212 return (float) fmin( (double)x, (double)y );
214 #endif
216 #ifdef L_fmodf
217 float fmodf (float x, float y)
219 return (float) fmod( (double)x, (double)y );
221 #endif
223 #ifdef L_frexpf
224 float frexpf (float x, int *_exp)
226 return (float) frexp( (double)x, _exp );
228 #endif
230 #ifdef L_hypotf
231 float hypotf (float x, float y)
233 return (float) hypot( (double)x, (double)y );
235 #endif
237 #ifdef L_ilogbf
238 int_WRAPPER1(ilogb)
239 #endif
241 #ifdef L_j0f
242 WRAPPER1(j0)
243 #endif
245 #ifdef L_j1f
246 WRAPPER1(j1)
247 #endif
249 #ifdef L_jnf
250 float jnf(int n, float x)
252 return (float) jn(n, (double)x);
254 #endif
256 #ifdef L_ldexpf
257 float ldexpf (float x, int _exp)
259 return (float) ldexp( (double)x, _exp );
261 #endif
263 #ifdef L_lgammaf
264 WRAPPER1(lgamma)
265 #endif
267 #ifdef L_llrintf
268 long_long_WRAPPER1(llrint)
269 #endif
271 #ifdef L_llroundf
272 long_long_WRAPPER1(llround)
273 #endif
275 #ifdef L_log10f
276 WRAPPER1(log10)
277 #endif
279 #ifdef L_log1pf
280 WRAPPER1(log1p)
281 #endif
283 #ifdef L_log2f
284 WRAPPER1(log2)
285 #endif
287 #ifdef L_logbf
288 WRAPPER1(logb)
289 #endif
291 #ifdef L_logf
292 WRAPPER1(log)
293 #endif
295 #ifdef L_lrintf
296 long_WRAPPER1(lrint)
297 #endif
299 #ifdef L_lroundf
300 long_WRAPPER1(lround)
301 #endif
303 #ifdef L_modff
304 float modff (float x, float *iptr)
306 double y, result;
307 result = modf( x, &y );
308 *iptr = (float)y;
309 return (float) result;
311 #endif
313 #ifdef L_nearbyintf
314 WRAPPER1(nearbyint)
315 #endif
317 #ifdef L_nexttowardf
318 float nexttowardf (float x, long double y)
320 return (float) nexttoward( (double)x, (long double)y );
322 #endif
324 #ifdef L_powf
325 float powf (float x, float y)
327 return (float) pow( (double)x, (double)y );
329 #endif
331 #ifdef L_remainderf
332 float remainderf (float x, float y)
334 return (float) remainder( (double)x, (double)y );
336 #endif
338 #ifdef L_remquof
339 float remquof (float x, float y, int *quo)
341 return (float) remquo( (double)x, (double)y, quo );
343 #endif
345 #ifdef L_rintf
346 WRAPPER1(rint)
347 #endif
349 #ifdef L_roundf
350 WRAPPER1(round)
351 #endif
353 #ifdef L_scalblnf
354 float scalblnf (float x, long _exp)
356 return (float) scalbln( (double)x, _exp );
358 #endif
360 #ifdef L_scalbnf
361 float scalbnf (float x, int _exp)
363 return (float) scalbn( (double)x, _exp );
365 #endif
367 #ifdef L_sinf
368 WRAPPER1(sin)
369 libm_hidden_def(sinf)
370 #endif
372 #ifdef L_sinhf
373 WRAPPER1(sinh)
374 #endif
376 #ifdef L_sqrtf
377 WRAPPER1(sqrt)
378 #endif
380 #ifdef L_tanf
381 WRAPPER1(tan)
382 #endif
384 #ifdef L_tanhf
385 WRAPPER1(tanh)
386 #endif
388 #ifdef L_tgammaf
389 WRAPPER1(tgamma)
390 #endif
392 #ifdef L_truncf
393 WRAPPER1(trunc)
394 #endif
396 #if defined L_scalbf && defined __UCLIBC_SUSV3_LEGACY__
397 float scalbf (float x, float y)
399 return (float) scalb( (double)x, (double)y );
401 #endif
403 #ifdef L_gammaf
404 WRAPPER1(gamma)
405 #endif
407 #ifdef L_significandf
408 WRAPPER1(significand)
409 #endif
411 #ifdef L_y0f
412 WRAPPER1(y0)
413 #endif
415 #ifdef L_y1f
416 WRAPPER1(y1)
417 #endif
419 #ifdef L_ynf
420 float ynf(int n, float x)
422 return (float) yn(n, (double)x);
424 #endif