]> rtime.felk.cvut.cz Git - l4.git/blob - l4/pkg/uclibc/lib/contrib/uclibc/libm/float_wrappers.c
a13aac93aa25e7dd5d5e7dfe16ecc17845b10be2
[l4.git] / l4 / pkg / uclibc / lib / contrib / uclibc / libm / float_wrappers.c
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.
7  *
8  * Copyright (C) 2005 by Erik Andersen <andersen@uclibc.org>
9  *
10  * GNU Lesser General Public License version 2.1 or later.
11  */
12
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>
18
19
20 #define WRAPPER1(func) \
21 float func##f (float x) \
22 { \
23         return (float) func((double)x); \
24 }
25 #define int_WRAPPER1(func) \
26 int func##f (float x) \
27 { \
28         return func((double)x); \
29 }
30 #define long_WRAPPER1(func) \
31 long func##f (float x) \
32 { \
33         return func((double)x); \
34 }
35 #define long_long_WRAPPER1(func) \
36 long long func##f (float x) \
37 { \
38         return func((double)x); \
39 }
40
41
42 /* For the time being, do _NOT_ implement these functions
43  * that are defined by SuSv3 [because we don't need them
44  * and nobody asked to include them] */
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_nearbyintf    /*float       nearbyintf(float);*/
50 #undef L_nexttowardf   /*float       nexttowardf(float, long double);*/
51 #undef L_remquof       /*float       remquof(float, float, int *);*/
52 #undef L_scalblnf      /*float       scalblnf(float, long);*/
53 #undef L_tgammaf       /*float       tgammaf(float);*/
54
55 /* Implement the following, as defined by SuSv3 */
56 #if 0
57 float       acosf(float);
58 float       acoshf(float);
59 float       asinf(float);
60 float       asinhf(float);
61 float       atan2f(float, float);
62 float       atanf(float);
63 float       atanhf(float);
64 float       cargf(float complex);
65 float       cbrtf(float);
66 float       ceilf(float);
67 float       copysignf(float, float);
68 float       cosf(float);
69 float       coshf(float);
70 float       erfcf(float);
71 float       erff(float);
72 float       exp2f(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       log2f(float);
87 float       logbf(float);
88 float       logf(float);
89 long        lroundf(float);
90 float       modff(float, float *);
91 float       powf(float, float);
92 float       remainderf(float, float);
93 float       rintf(float);
94 float       roundf(float);
95 float       scalbnf(float, int);
96 float       sinf(float);
97 float       sinhf(float);
98 float       sqrtf(float);
99 float       tanf(float);
100 float       tanhf(float);
101 #endif
102
103 #ifdef L_acosf
104 WRAPPER1(acos)
105 #endif
106
107 #ifdef L_acoshf
108 WRAPPER1(acosh)
109 #endif
110
111 #ifdef L_asinf
112 WRAPPER1(asin)
113 #endif
114
115 #ifdef L_asinhf
116 WRAPPER1(asinh)
117 #endif
118
119 #ifdef L_atan2f
120 float atan2f (float x, float y)
121 {
122         return (float) atan2( (double)x, (double)y );
123 }
124 #endif
125
126 #ifdef L_atanf
127 WRAPPER1(atan)
128 #endif
129
130 #ifdef L_atanhf
131 WRAPPER1(atanh)
132 #endif
133
134 #ifdef L_cargf
135 float cargf (float complex x)
136 {
137         return (float) carg( (double complex)x );
138 }
139 #endif
140
141 #ifdef L_cbrtf
142 WRAPPER1(cbrt)
143 #endif
144
145 #ifdef L_ceilf
146 WRAPPER1(ceil)
147 #endif
148
149 #ifdef L_copysignf
150 float copysignf (float x, float y)
151 {
152         return (float) copysign( (double)x, (double)y );
153 }
154 #endif
155
156 #ifdef L_cosf
157 WRAPPER1(cos)
158 #endif
159
160 #ifdef L_coshf
161 WRAPPER1(cosh)
162 #endif
163
164 #ifdef L_erfcf
165 WRAPPER1(erfc)
166 #endif
167
168 #ifdef L_erff
169 WRAPPER1(erf)
170 #endif
171
172 #ifdef L_exp2f
173 WRAPPER1(exp2)
174 #endif
175
176 #ifdef L_expf
177 WRAPPER1(exp)
178 #endif
179
180 #ifdef L_expm1f
181 WRAPPER1(expm1)
182 #endif
183
184 #ifdef L_fabsf
185 WRAPPER1(fabs)
186 #endif
187
188 #ifdef L_fdimf
189 float fdimf (float x, float y)
190 {
191         return (float) fdim( (double)x, (double)y );
192 }
193 #endif
194
195 #ifdef L_floorf
196 WRAPPER1(floor)
197 #endif
198
199 #ifdef L_fmaf
200 float fmaf (float x, float y, float z)
201 {
202         return (float) fma( (double)x, (double)y, (double)z );
203 }
204 #endif
205
206 #ifdef L_fmaxf
207 float fmaxf (float x, float y)
208 {
209         return (float) fmax( (double)x, (double)y );
210 }
211 #endif
212
213 #ifdef L_fminf
214 float fminf (float x, float y)
215 {
216         return (float) fmin( (double)x, (double)y );
217 }
218 #endif
219
220 #ifdef L_fmodf
221 float fmodf (float x, float y)
222 {
223         return (float) fmod( (double)x, (double)y );
224 }
225 #endif
226
227 #ifdef L_frexpf
228 float frexpf (float x, int *_exp)
229 {
230         return (float) frexp( (double)x, _exp );
231 }
232 #endif
233
234 #ifdef L_hypotf
235 float hypotf (float x, float y)
236 {
237         return (float) hypot( (double)x, (double)y );
238 }
239 #endif
240
241 #ifdef L_ilogbf
242 int_WRAPPER1(ilogb)
243 #endif
244
245 #ifdef L_ldexpf
246 float ldexpf (float x, int _exp)
247 {
248         return (float) ldexp( (double)x, _exp );
249 }
250 #endif
251
252 #ifdef L_lgammaf
253 WRAPPER1(lgamma)
254 #endif
255
256 #ifdef L_llrintf
257 long_long_WRAPPER1(llrint)
258 #endif
259
260 #ifdef L_llroundf
261 long_long_WRAPPER1(llround)
262 #endif
263
264 #ifdef L_log10f
265 WRAPPER1(log10)
266 #endif
267
268 #ifdef L_log1pf
269 WRAPPER1(log1p)
270 #endif
271
272 #ifdef L_log2f
273 WRAPPER1(log2)
274 #endif
275
276 #ifdef L_logbf
277 WRAPPER1(logb)
278 #endif
279
280 #ifdef L_logf
281 WRAPPER1(log)
282 #endif
283
284 #ifdef L_lrintf
285 long_WRAPPER1(lrint)
286 #endif
287
288 #ifdef L_lroundf
289 long_WRAPPER1(lround)
290 #endif
291
292 #ifdef L_modff
293 float modff (float x, float *iptr)
294 {
295         double y, result;
296         result = modf ( x, &y );
297         *iptr = (float)y;
298         return (float) result;
299
300 }
301 #endif
302
303 #ifdef L_nearbyintf
304 WRAPPER1(nearbyint)
305 #endif
306
307 #ifdef L_nexttowardf
308 float nexttowardf (float x, long double y)
309 {
310         return (float) nexttoward( (double)x, (double)y );
311 }
312 #endif
313
314 #ifdef L_powf
315 float powf (float x, float y)
316 {
317         return (float) pow( (double)x, (double)y );
318 }
319 #endif
320
321 #ifdef L_remainderf
322 float remainderf (float x, float y)
323 {
324         return (float) remainder( (double)x, (double)y );
325 }
326 #endif
327
328 #ifdef L_remquof
329 float remquof (float x, float y, int *quo)
330 {
331         return (float) remquo( (double)x, (double)y, quo );
332 }
333 #endif
334
335 #ifdef L_rintf
336 WRAPPER1(rint)
337 #endif
338
339 #ifdef L_roundf
340 WRAPPER1(round)
341 #endif
342
343 #ifdef L_scalblnf
344 float scalblnf (float x, long _exp)
345 {
346         return (float) scalbln( (double)x, _exp );
347 }
348 #endif
349
350 #ifdef L_scalbnf
351 float scalbnf (float x, int _exp)
352 {
353         return (float) scalbn( (double)x, _exp );
354 }
355 #endif
356
357 #ifdef L_sinf
358 WRAPPER1(sin)
359 #endif
360
361 #ifdef L_sinhf
362 WRAPPER1(sinh)
363 #endif
364
365 #ifdef L_sqrtf
366 WRAPPER1(sqrt)
367 #endif
368
369 #ifdef L_tanf
370 WRAPPER1(tan)
371 #endif
372
373 #ifdef L_tanhf
374 WRAPPER1(tanh)
375 #endif
376
377 #ifdef L_tgammaf
378 WRAPPER1(tgamma)
379 #endif
380
381 #ifdef L_truncf
382 WRAPPER1(trunc)
383 #endif
384
385 #ifdef L_fmaf
386 float fmaf (float x, float y, float z)
387 {
388         return (float) fma( (double)x, (double)y, (double)z );
389 }
390 #endif
391
392 #if defined L_scalbf && defined __UCLIBC_SUSV3_LEGACY__
393 float scalbf (float x, float y)
394 {
395         return (float) scalb( (double)x, (double)y );
396 }
397 #endif
398
399 #ifdef L_gammaf
400 WRAPPER1(gamma)
401 #endif
402
403 #ifdef L_significandf
404 WRAPPER1(significand)
405 #endif