1 /*
2  * Wrapper functions implementing all the float math functions
3  * defined by SuSv3 by actually calling the double version of
4  * each function and then casting the result back to a float
5  * to return to the user.
6  *
7  * Copyright (C) 2005 by Erik Andersen <andersen@uclibc.org>
8  *
9  * GNU Lesser General Public License version 2.1 or later.
10  */
11 
12 #include <features.h>
13 /* Prevent math.h from defining colliding inlines */
14 #undef __USE_EXTERN_INLINES
15 #include <math.h>
16 #include <complex.h>
17 
18 
19 #define WRAPPER1(func) \
20 float func##f (float x) \
21 { \
22 	return (float) func((double)x); \
23 }
24 #define int_WRAPPER1(func) \
25 int func##f (float x) \
26 { \
27 	return func((double)x); \
28 }
29 #define long_WRAPPER1(func) \
30 long func##f (float x) \
31 { \
32 	return func((double)x); \
33 }
34 #define long_long_WRAPPER1(func) \
35 long long func##f (float x) \
36 { \
37 	return func((double)x); \
38 }
39 
40 /* Implement the following, as defined by SuSv3 */
41 #if 0
42 float       asinhf(float);
43 float       atanf(float);
44 float       cargf(float complex);
45 float       cbrtf(float);
46 float       ceilf(float);
47 float       copysignf(float, float);
48 float       cosf(float);
49 float       erfcf(float);
50 float       erff(float);
51 float       expm1f(float);
52 float       fabsf(float);
53 float       floorf(float);
54 float       frexpf(float value, int *);
55 int         ilogbf(float);
56 float       ldexpf(float, int);
57 long long   llroundf(float);
58 float       log1pf(float);
59 float       logbf(float);
60 long        lroundf(float);
61 float       modff(float, float *);
62 float       rintf(float);
63 float       roundf(float);
64 float       scalbnf(float, int);
65 float       sinf(float);
66 float       tanf(float);
67 float       tanhf(float);
68 #endif
69 
70 /* The following functions implemented as wrappers
71  * in separate files (w_funcf.c)
72  */
73 #if 0
74 float       acosf(float);
75 float       acoshf(float);
76 float       asinf(float);
77 float       atan2f(float, float);
78 float       atanhf(float);
79 float       coshf(float);
80 float       exp2f(float);
81 float       expf(float);
82 float       fmodf(float, float);
83 float       hypotf(float, float);
84 float       lgammaf(float);
85 float       log10f(float);
86 float       log2f(float);
87 float       logf(float);
88 float       powf(float, float);
89 float       remainderf(float, float);
90 float       sinhf(float);
91 float       sqrtf(float);
92 float		j0f(float x);
93 float		j1f(float x);
94 float		jnf(int n, float x);
95 float		y0f(float x);
96 float		y1f(float x);
97 float		ynf(int n, float x);
98 float 		tgammaf(float x);
99 float 		scalbf(float x, float fn);
100 float 		gammaf(float x);
101 float	 	scalbl(float x, float fn);
102 #endif
103 
104 #ifdef L_asinhf
105 WRAPPER1(asinh)
106 #endif
107 
108 #ifdef L_atanf
WRAPPER1(atan)109 WRAPPER1(atan)
110 #endif
111 
112 #ifdef L_cargf
113 float cargf (float complex x)
114 {
115 	return (float) carg( (double complex)x );
116 }
117 #endif
118 
119 #ifdef L_cbrtf
120 WRAPPER1(cbrt)
121 #endif
122 
123 #ifdef L_ceilf
WRAPPER1(ceil)124 WRAPPER1(ceil)
125 #endif
126 
127 #ifdef L_copysignf
128 float copysignf (float x, float y)
129 {
130 	return (float) copysign( (double)x, (double)y );
131 }
132 #endif
133 
134 #ifdef L_cosf
135 WRAPPER1(cos)
libm_hidden_def(cosf)136 libm_hidden_def(cosf)
137 #endif
138 
139 #ifdef L_erfcf
140 WRAPPER1(erfc)
141 #endif
142 
143 #ifdef L_erff
144 WRAPPER1(erf)
145 #endif
146 
147 #ifdef L_expm1f
148 WRAPPER1(expm1)
149 #endif
150 
151 #ifdef L_fabsf
152 WRAPPER1(fabs)
153 #endif
154 
155 #ifdef L_fdimf
156 float fdimf (float x, float y)
157 {
158 	return (float) fdim( (double)x, (double)y );
159 }
160 #endif
161 
162 #ifdef L_floorf
WRAPPER1(floor)163 WRAPPER1(floor)
164 #endif
165 
166 #ifdef L_fmaf
167 float fmaf (float x, float y, float z)
168 {
169 	return (float) fma( (double)x, (double)y, (double)z );
170 }
171 #endif
172 
173 #ifdef L_fmaxf
fmaxf(float x,float y)174 float fmaxf (float x, float y)
175 {
176 	return (float) fmax( (double)x, (double)y );
177 }
178 #endif
179 
180 #ifdef L_fminf
fminf(float x,float y)181 float fminf (float x, float y)
182 {
183 	return (float) fmin( (double)x, (double)y );
184 }
185 #endif
186 
187 #ifdef L_frexpf
frexpf(float x,int * _exp)188 float frexpf (float x, int *_exp)
189 {
190 	return (float) frexp( (double)x, _exp );
191 }
192 #endif
193 
194 #ifdef L_ilogbf
int_WRAPPER1(ilogb)195 int_WRAPPER1(ilogb)
196 #endif
197 
198 #ifdef L_ldexpf
199 float ldexpf (float x, int _exp)
200 {
201 	return (float) ldexp( (double)x, _exp );
202 }
203 #endif
204 
205 #ifdef L_llrintf
206 long_long_WRAPPER1(llrint)
207 #endif
208 
209 #ifdef L_llroundf
long_long_WRAPPER1(llround)210 long_long_WRAPPER1(llround)
211 #endif
212 
213 #ifdef L_log1pf
214 WRAPPER1(log1p)
215 #endif
216 
217 #ifdef L_logbf
218 WRAPPER1(logb)
219 #endif
220 
221 #ifdef L_lrintf
222 long_WRAPPER1(lrint)
223 #endif
224 
225 #ifdef L_lroundf
226 long_WRAPPER1(lround)
227 #endif
228 
229 #ifdef L_modff
230 float modff (float x, float *iptr)
231 {
232 	double y, result;
233 	result = modf( (double)x, &y );
234 	*iptr = (float)y;
235 	return (float) result;
236 }
237 #endif
238 
239 #ifdef L_nearbyintf
WRAPPER1(nearbyint)240 WRAPPER1(nearbyint)
241 #endif
242 
243 #ifdef L_nexttowardf
244 float nexttowardf (float x, long double y)
245 {
246 	return (float) nexttoward( (double)x, (long double)y );
247 }
248 #endif
249 
250 #ifdef L_remquof
remquof(float x,float y,int * quo)251 float remquof (float x, float y, int *quo)
252 {
253 	return (float) remquo( (double)x, (double)y, quo );
254 }
255 #endif
256 
257 #ifdef L_rintf
258 WRAPPER1(rint)
259 #endif
260 
261 #ifdef L_roundf
WRAPPER1(round)262 WRAPPER1(round)
263 #endif
264 
265 #ifdef L_scalblnf
266 float scalblnf (float x, long _exp)
267 {
268 	return (float) scalbln( (double)x, _exp );
269 }
270 #endif
271 
272 #ifdef L_scalbnf
scalbnf(float x,int _exp)273 float scalbnf (float x, int _exp)
274 {
275 	return (float) scalbn( (double)x, _exp );
276 }
277 #endif
278 
279 #ifdef L_sinf
280 WRAPPER1(sin)
281 libm_hidden_def(sinf)
282 #endif
283 
284 #ifdef L_tanf
285 WRAPPER1(tan)
286 #endif
287 
288 #ifdef L_tanhf
289 WRAPPER1(tanh)
290 #endif
291 
292 #ifdef L_truncf
293 WRAPPER1(trunc)
294 #endif
295 
296 #ifdef L_significandf
297 WRAPPER1(significand)
298 #endif
299