OSDN Git Service

- scalb{,f,l} depend on UCLIBC_SUSV3_LEGACY
[uclinux-h8/uClibc.git] / 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 [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);*/
55
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
101
102 #ifdef L_acosf
103 WRAPPER1(acos)
104 #endif
105
106 #ifdef L_acoshf
107 WRAPPER1(acosh)
108 #endif
109
110 #ifdef L_asinf
111 WRAPPER1(asin)
112 #endif
113
114 #ifdef L_asinhf
115 WRAPPER1(asinh)
116 #endif
117
118 #ifdef L_atan2f
119 float atan2f (float x, float y)
120 {
121         return (float) atan2( (double)x, (double)y );
122 }
123 #endif
124
125 #ifdef L_atanf
126 WRAPPER1(atan)
127 #endif
128
129 #ifdef L_atanhf
130 WRAPPER1(atanh)
131 #endif
132
133 #ifdef L_cargf
134 float cargf (float complex x)
135 {
136         return (float) carg( (double complex)x );
137 }
138 #endif
139
140 #ifdef L_cbrtf
141 WRAPPER1(cbrt)
142 #endif
143
144 #ifdef L_ceilf
145 WRAPPER1(ceil)
146 #endif
147
148 #ifdef L_copysignf
149 float copysignf (float x, float y)
150 {
151         return (float) copysign( (double)x, (double)y );
152 }
153 #endif
154
155 #ifdef L_cosf
156 WRAPPER1(cos)
157 #endif
158
159 #ifdef L_coshf
160 WRAPPER1(cosh)
161 #endif
162
163 #ifdef L_erfcf
164 WRAPPER1(erfc)
165 #endif
166
167 #ifdef L_erff
168 WRAPPER1(erf)
169 #endif
170
171 #ifdef L_exp2f
172 WRAPPER1(exp2)
173 #endif
174
175 #ifdef L_expf
176 WRAPPER1(exp)
177 #endif
178
179 #ifdef L_expm1f
180 WRAPPER1(expm1)
181 #endif
182
183 #ifdef L_fabsf
184 WRAPPER1(fabs)
185 #endif
186
187 #ifdef L_fdimf
188 float fdimf (float x, float y)
189 {
190         return (float) fdim( (double)x, (double)y );
191 }
192 #endif
193
194 #ifdef L_floorf
195 WRAPPER1(floor)
196 #endif
197
198 #ifdef L_fmaf
199 float fmaf (float x, float y, float z)
200 {
201         return (float) fma( (double)x, (double)y, (double)z );
202 }
203 #endif
204
205 #ifdef L_fmaxf
206 float fmaxf (float x, float y)
207 {
208         return (float) fmax( (double)x, (double)y );
209 }
210 #endif
211
212 #ifdef L_fminf
213 float fminf (float x, float y)
214 {
215         return (float) fmin( (double)x, (double)y );
216 }
217 #endif
218
219 #ifdef L_fmodf
220 float fmodf (float x, float y)
221 {
222         return (float) fmod( (double)x, (double)y );
223 }
224 #endif
225
226 #ifdef L_frexpf
227 float frexpf (float x, int *_exp)
228 {
229         return (float) frexp( (double)x, _exp );
230 }
231 #endif
232
233 #ifdef L_hypotf
234 float hypotf (float x, float y)
235 {
236         return (float) hypot( (double)x, (double)y );
237 }
238 #endif
239
240 #ifdef L_ilogbf
241 int_WRAPPER1(ilogb)
242 #endif
243
244 #ifdef L_ldexpf
245 float ldexpf (float x, int _exp)
246 {
247         return (float) ldexp( (double)x, _exp );
248 }
249 #endif
250
251 #ifdef L_lgammaf
252 WRAPPER1(lgamma)
253 #endif
254
255 #ifdef L_llrintf
256 long_long_WRAPPER1(llrint)
257 #endif
258
259 #ifdef L_llroundf
260 long_long_WRAPPER1(llround)
261 #endif
262
263 #ifdef L_log10f
264 WRAPPER1(log10)
265 #endif
266
267 #ifdef L_log1pf
268 WRAPPER1(log1p)
269 #endif
270
271 #ifdef L_log2f
272 WRAPPER1(log2)
273 #endif
274
275 #ifdef L_logbf
276 WRAPPER1(logb)
277 #endif
278
279 #ifdef L_logf
280 WRAPPER1(log)
281 #endif
282
283 #ifdef L_lrintf
284 long_WRAPPER1(lrint)
285 #endif
286
287 #ifdef L_lroundf
288 long_WRAPPER1(lround)
289 #endif
290
291 #ifdef L_modff
292 float modff (float x, float *iptr)
293 {
294         double y, result;
295         result = modf ( x, &y );
296         *iptr = (float)y;
297         return (float) result;
298
299 }
300 #endif
301
302 #ifdef L_nearbyintf
303 WRAPPER1(nearbyint)
304 #endif
305
306 #ifdef L_nexttowardf
307 float nexttowardf (float x, long double y)
308 {
309         return (float) nexttoward( (double)x, (double)y );
310 }
311 #endif
312
313 #ifdef L_powf
314 float powf (float x, float y)
315 {
316         return (float) pow( (double)x, (double)y );
317 }
318 #endif
319
320 #ifdef L_remainderf
321 float remainderf (float x, float y)
322 {
323         return (float) remainder( (double)x, (double)y );
324 }
325 #endif
326
327 #ifdef L_remquof
328 float remquof (float x, float y, int *quo)
329 {
330         return (float) remquo( (double)x, (double)y, quo );
331 }
332 #endif
333
334 #ifdef L_rintf
335 WRAPPER1(rint)
336 #endif
337
338 #ifdef L_roundf
339 WRAPPER1(round)
340 #endif
341
342 #ifdef L_scalblnf
343 float scalblnf (float x, long _exp)
344 {
345         return (float) scalbln( (double)x, _exp );
346 }
347 #endif
348
349 #ifdef L_scalbnf
350 float scalbnf (float x, int _exp)
351 {
352         return (float) scalbn( (double)x, _exp );
353 }
354 #endif
355
356 #ifdef L_sinf
357 WRAPPER1(sin)
358 #endif
359
360 #ifdef L_sinhf
361 WRAPPER1(sinh)
362 #endif
363
364 #ifdef L_sqrtf
365 WRAPPER1(sqrt)
366 #endif
367
368 #ifdef L_tanf
369 WRAPPER1(tan)
370 #endif
371
372 #ifdef L_tanhf
373 WRAPPER1(tanh)
374 #endif
375
376 #ifdef L_tgammaf
377 WRAPPER1(tgamma)
378 #endif
379
380 #ifdef L_truncf
381 WRAPPER1(trunc)
382 #endif
383
384 #ifdef L_fmaf
385 float fmaf (float x, float y, float z)
386 {
387         return (float) fma( (double)x, (double)y, (double)z );
388 }
389 #endif
390
391 #if defined L_scalbf && defined __UCLIBC_SUSV3_LEGACY__
392 float scalbf (float x, float y)
393 {
394         return (float) scalb( (double)x, (double)y );
395 }
396 #endif
397
398 #ifdef L_gammaf
399 WRAPPER1(gamma)
400 #endif
401
402 #ifdef L_significandf
403 WRAPPER1(significand)
404 #endif