Rules.mak fix typo (qstrup -> qstrip)
[uclibc-ng.git] / libm / float_wrappers.c
blob93d56c3c9978fcf24b942dd970c45b22e1a14d01
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); \
42 /* For the time being, do _NOT_ implement these functions
43 * that are defined by SuSv3 [why?] */
44 #undef L_exp2f /*float exp2f(float);*/
45 #undef L_fdimf /*float fdimf(float, float);*/
46 #undef L_fmaf /*float fmaf(float, float, float);*/
47 #undef L_fmaxf /*float fmaxf(float, float);*/
48 #undef L_fminf /*float fminf(float, float);*/
49 #undef L_log2f /*float log2f(float);*/
50 #undef L_nearbyintf /*float nearbyintf(float);*/
51 #undef L_nexttowardf /*float nexttowardf(float, long double);*/
52 #undef L_remquof /*float remquof(float, float, int *);*/
53 #undef L_scalblnf /*float scalblnf(float, long);*/
54 #undef L_tgammaf /*float tgammaf(float);*/
56 /* Implement the following, as defined by SuSv3 */
57 #if 0
58 float acosf(float);
59 float acoshf(float);
60 float asinf(float);
61 float asinhf(float);
62 float atan2f(float, float);
63 float atanf(float);
64 float atanhf(float);
65 float cargf(float complex);
66 float cbrtf(float);
67 float ceilf(float);
68 float copysignf(float, float);
69 float cosf(float);
70 float coshf(float);
71 float erfcf(float);
72 float erff(float);
73 float expf(float);
74 float expm1f(float);
75 float fabsf(float);
76 float floorf(float);
77 float fmodf(float, float);
78 float frexpf(float value, int *);
79 float hypotf(float, float);
80 int ilogbf(float);
81 float ldexpf(float, int);
82 float lgammaf(float);
83 long long llroundf(float);
84 float log10f(float);
85 float log1pf(float);
86 float logbf(float);
87 float logf(float);
88 long lroundf(float);
89 float modff(float, float *);
90 float powf(float, float);
91 float remainderf(float, float);
92 float rintf(float);
93 float roundf(float);
94 float scalbnf(float, int);
95 float sinf(float);
96 float sinhf(float);
97 float sqrtf(float);
98 float tanf(float);
99 float tanhf(float);
100 #endif
102 #ifdef L_acosf
103 WRAPPER1(acos)
104 #endif
106 #ifdef L_acoshf
107 WRAPPER1(acosh)
108 #endif
110 #ifdef L_asinf
111 WRAPPER1(asin)
112 #endif
114 #ifdef L_asinhf
115 WRAPPER1(asinh)
116 #endif
118 #ifdef L_atan2f
119 float atan2f (float x, float y)
121 return (float) atan2( (double)x, (double)y );
123 #endif
125 #ifdef L_atanf
126 WRAPPER1(atan)
127 #endif
129 #ifdef L_atanhf
130 WRAPPER1(atanh)
131 #endif
133 #ifdef L_cargf
134 float cargf (float complex x)
136 return (float) carg( (double complex)x );
138 #endif
140 #ifdef L_cbrtf
141 WRAPPER1(cbrt)
142 #endif
144 #ifdef L_ceilf
145 WRAPPER1(ceil)
146 #endif
148 #ifdef L_copysignf
149 float copysignf (float x, float y)
151 return (float) copysign( (double)x, (double)y );
153 #endif
155 #ifdef L_cosf
156 WRAPPER1(cos)
157 #endif
159 #ifdef L_coshf
160 WRAPPER1(cosh)
161 #endif
163 #ifdef L_erfcf
164 WRAPPER1(erfc)
165 #endif
167 #ifdef L_erff
168 WRAPPER1(erf)
169 #endif
171 #ifdef L_exp2f
172 WRAPPER1(exp2)
173 #endif
175 #ifdef L_expf
176 WRAPPER1(exp)
177 #endif
179 #ifdef L_expm1f
180 WRAPPER1(expm1)
181 #endif
183 #ifdef L_fabsf
184 WRAPPER1(fabs)
185 #endif
187 #ifdef L_fdimf
188 float fdimf (float x, float y)
190 return (float) fdim( (double)x, (double)y );
192 #endif
194 #ifdef L_floorf
195 WRAPPER1(floor)
196 #endif
198 #ifdef L_fmaf
199 float fmaf (float x, float y, float z)
201 return (float) fma( (double)x, (double)y, (double)z );
203 #endif
205 #ifdef L_fmaxf
206 float fmaxf (float x, float y)
208 return (float) fmax( (double)x, (double)y );
210 #endif
212 #ifdef L_fminf
213 float fminf (float x, float y)
215 return (float) fmin( (double)x, (double)y );
217 #endif
219 #ifdef L_fmodf
220 float fmodf (float x, float y)
222 return (float) fmod( (double)x, (double)y );
224 #endif
226 #ifdef L_frexpf
227 float frexpf (float x, int *_exp)
229 return (float) frexp( (double)x, _exp );
231 #endif
233 #ifdef L_hypotf
234 float hypotf (float x, float y)
236 return (float) hypot( (double)x, (double)y );
238 #endif
240 #ifdef L_ilogbf
241 int_WRAPPER1(ilogb)
242 #endif
244 #ifdef L_ldexpf
245 float ldexpf (float x, int _exp)
247 return (float) ldexp( (double)x, _exp );
249 #endif
251 #ifdef L_lgammaf
252 WRAPPER1(lgamma)
253 #endif
255 #ifdef L_llrintf
256 long_long_WRAPPER1(llrint)
257 #endif
259 #ifdef L_llroundf
260 long_long_WRAPPER1(llround)
261 #endif
263 #ifdef L_log10f
264 WRAPPER1(log10)
265 #endif
267 #ifdef L_log1pf
268 WRAPPER1(log1p)
269 #endif
271 #ifdef L_log2f
272 WRAPPER1(log2)
273 #endif
275 #ifdef L_logbf
276 WRAPPER1(logb)
277 #endif
279 #ifdef L_logf
280 WRAPPER1(log)
281 #endif
283 #ifdef L_lrintf
284 long_WRAPPER1(lrint)
285 #endif
287 #ifdef L_lroundf
288 long_WRAPPER1(lround)
289 #endif
291 #ifdef L_modff
292 float modff (float x, float *iptr)
294 double y, result;
295 result = modf ( x, &y );
296 *iptr = (float)y;
297 return (float) result;
300 #endif
302 #ifdef L_nearbyintf
303 WRAPPER1(nearbyint)
304 #endif
306 #ifdef L_nexttowardf
307 float nexttowardf (float x, long double y)
309 return (float) nexttoward( (double)x, (double)y );
311 #endif
313 #ifdef L_powf
314 float powf (float x, float y)
316 return (float) pow( (double)x, (double)y );
318 #endif
320 #ifdef L_remainderf
321 float remainderf (float x, float y)
323 return (float) remainder( (double)x, (double)y );
325 #endif
327 #ifdef L_remquof
328 float remquof (float x, float y, int *quo)
330 return (float) remquo( (double)x, (double)y, quo );
332 #endif
334 #ifdef L_rintf
335 WRAPPER1(rint)
336 #endif
338 #ifdef L_roundf
339 WRAPPER1(round)
340 #endif
342 #ifdef L_scalblnf
343 float scalblnf (float x, long _exp)
345 return (float) scalbln( (double)x, _exp );
347 #endif
349 #ifdef L_scalbnf
350 float scalbnf (float x, int _exp)
352 return (float) scalbn( (double)x, _exp );
354 #endif
356 #ifdef L_sinf
357 WRAPPER1(sin)
358 #endif
360 #ifdef L_sinhf
361 WRAPPER1(sinh)
362 #endif
364 #ifdef L_sqrtf
365 WRAPPER1(sqrt)
366 #endif
368 #ifdef L_tanf
369 WRAPPER1(tan)
370 #endif
372 #ifdef L_tanhf
373 WRAPPER1(tanh)
374 #endif
376 #ifdef L_tgammaf
377 WRAPPER1(tgamma)
378 #endif
380 #ifdef L_truncf
381 WRAPPER1(trunc)
382 #endif
384 #ifdef L_fmaf
385 float fmaf (float x, float y, float z)
387 return (float) fma( (double)x, (double)y, (double)z );
389 #endif
391 #if defined L_scalbf && defined __UCLIBC_SUSV3_LEGACY__
392 float scalbf (float x, float y)
394 return (float) scalb( (double)x, (double)y );
396 #endif
398 #ifdef L_gammaf
399 WRAPPER1(gamma)
400 #endif
402 #ifdef L_significandf
403 WRAPPER1(significand)
404 #endif