blob: 82b7963e11836090153b91150c54a645201db692 [file] [log] [blame]
lh9ed821d2023-04-07 01:36:19 -07001/* 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) \
21float func##f (float x) \
22{ \
23 return (float) func((double)x); \
24}
25#define int_WRAPPER1(func) \
26int func##f (float x) \
27{ \
28 return func((double)x); \
29}
30#define long_WRAPPER1(func) \
31long func##f (float x) \
32{ \
33 return func((double)x); \
34}
35#define long_long_WRAPPER1(func) \
36long 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
57float acosf(float);
58float acoshf(float);
59float asinf(float);
60float asinhf(float);
61float atan2f(float, float);
62float atanf(float);
63float atanhf(float);
64float cargf(float complex);
65float cbrtf(float);
66float ceilf(float);
67float copysignf(float, float);
68float cosf(float);
69float coshf(float);
70float erfcf(float);
71float erff(float);
72float exp2f(float);
73float expf(float);
74float expm1f(float);
75float fabsf(float);
76float floorf(float);
77float fmodf(float, float);
78float frexpf(float value, int *);
79float hypotf(float, float);
80int ilogbf(float);
81float ldexpf(float, int);
82float lgammaf(float);
83long long llroundf(float);
84float log10f(float);
85float log1pf(float);
86float log2f(float);
87float logbf(float);
88float logf(float);
89long lroundf(float);
90float modff(float, float *);
91float powf(float, float);
92float remainderf(float, float);
93float rintf(float);
94float roundf(float);
95float scalbnf(float, int);
96float sinf(float);
97float sinhf(float);
98float sqrtf(float);
99float tanf(float);
100float tanhf(float);
101#endif
102
103#ifdef L_acosf
104WRAPPER1(acos)
105#endif
106
107#ifdef L_acoshf
108WRAPPER1(acosh)
109#endif
110
111#ifdef L_asinf
112WRAPPER1(asin)
113#endif
114
115#ifdef L_asinhf
116WRAPPER1(asinh)
117#endif
118
119#ifdef L_atan2f
120float atan2f (float x, float y)
121{
122 return (float) atan2( (double)x, (double)y );
123}
124#endif
125
126#ifdef L_atanf
127WRAPPER1(atan)
128#endif
129
130#ifdef L_atanhf
131WRAPPER1(atanh)
132#endif
133
134#ifdef L_cargf
135float cargf (float complex x)
136{
137 return (float) carg( (double complex)x );
138}
139#endif
140
141#ifdef L_cbrtf
142WRAPPER1(cbrt)
143#endif
144
145#ifdef L_ceilf
146WRAPPER1(ceil)
147#endif
148
149#ifdef L_copysignf
150float copysignf (float x, float y)
151{
152 return (float) copysign( (double)x, (double)y );
153}
154#endif
155
156#ifdef L_cosf
157WRAPPER1(cos)
158#endif
159
160#ifdef L_coshf
161WRAPPER1(cosh)
162#endif
163
164#ifdef L_erfcf
165WRAPPER1(erfc)
166#endif
167
168#ifdef L_erff
169WRAPPER1(erf)
170#endif
171
172#ifdef L_exp2f
173WRAPPER1(exp2)
174#endif
175
176#ifdef L_expf
177WRAPPER1(exp)
178#endif
179
180#ifdef L_expm1f
181WRAPPER1(expm1)
182#endif
183
184#ifdef L_fabsf
185WRAPPER1(fabs)
186#endif
187
188#ifdef L_fdimf
189float fdimf (float x, float y)
190{
191 return (float) fdim( (double)x, (double)y );
192}
193#endif
194
195#ifdef L_floorf
196WRAPPER1(floor)
197#endif
198
199#ifdef L_fmaf
200float 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
207float fmaxf (float x, float y)
208{
209 return (float) fmax( (double)x, (double)y );
210}
211#endif
212
213#ifdef L_fminf
214float fminf (float x, float y)
215{
216 return (float) fmin( (double)x, (double)y );
217}
218#endif
219
220#ifdef L_fmodf
221float fmodf (float x, float y)
222{
223 return (float) fmod( (double)x, (double)y );
224}
225#endif
226
227#ifdef L_frexpf
228float frexpf (float x, int *_exp)
229{
230 return (float) frexp( (double)x, _exp );
231}
232#endif
233
234#ifdef L_hypotf
235float hypotf (float x, float y)
236{
237 return (float) hypot( (double)x, (double)y );
238}
239#endif
240
241#ifdef L_ilogbf
242int_WRAPPER1(ilogb)
243#endif
244
245#ifdef L_ldexpf
246float ldexpf (float x, int _exp)
247{
248 return (float) ldexp( (double)x, _exp );
249}
250#endif
251
252#ifdef L_lgammaf
253WRAPPER1(lgamma)
254#endif
255
256#ifdef L_llrintf
257long_long_WRAPPER1(llrint)
258#endif
259
260#ifdef L_llroundf
261long_long_WRAPPER1(llround)
262#endif
263
264#ifdef L_log10f
265WRAPPER1(log10)
266#endif
267
268#ifdef L_log1pf
269WRAPPER1(log1p)
270#endif
271
272#ifdef L_log2f
273WRAPPER1(log2)
274#endif
275
276#ifdef L_logbf
277WRAPPER1(logb)
278#endif
279
280#ifdef L_logf
281WRAPPER1(log)
282#endif
283
284#ifdef L_lrintf
285long_WRAPPER1(lrint)
286#endif
287
288#ifdef L_lroundf
289long_WRAPPER1(lround)
290#endif
291
292#ifdef L_modff
293float 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#endif
301
302#ifdef L_nearbyintf
303WRAPPER1(nearbyint)
304#endif
305
306#ifdef L_nexttowardf
307float nexttowardf (float x, long double y)
308{
309 return (float) nexttoward( (double)x, (double)y );
310}
311#endif
312
313#ifdef L_powf
314float powf (float x, float y)
315{
316 return (float) pow( (double)x, (double)y );
317}
318#endif
319
320#ifdef L_remainderf
321float remainderf (float x, float y)
322{
323 return (float) remainder( (double)x, (double)y );
324}
325#endif
326
327#ifdef L_remquof
328float 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
335WRAPPER1(rint)
336#endif
337
338#ifdef L_roundf
339WRAPPER1(round)
340#endif
341
342#ifdef L_scalblnf
343float scalblnf (float x, long _exp)
344{
345 return (float) scalbln( (double)x, _exp );
346}
347#endif
348
349#ifdef L_scalbnf
350float scalbnf (float x, int _exp)
351{
352 return (float) scalbn( (double)x, _exp );
353}
354#endif
355
356#ifdef L_sinf
357WRAPPER1(sin)
358#endif
359
360#ifdef L_sinhf
361WRAPPER1(sinh)
362#endif
363
364#ifdef L_sqrtf
365WRAPPER1(sqrt)
366#endif
367
368#ifdef L_tanf
369WRAPPER1(tan)
370#endif
371
372#ifdef L_tanhf
373WRAPPER1(tanh)
374#endif
375
376#ifdef L_tgammaf
377WRAPPER1(tgamma)
378#endif
379
380#ifdef L_truncf
381WRAPPER1(trunc)
382#endif
383
384#ifdef L_fmaf
385float 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__
392float scalbf (float x, float y)
393{
394 return (float) scalb( (double)x, (double)y );
395}
396#endif
397
398#ifdef L_gammaf
399WRAPPER1(gamma)
400#endif
401
402#ifdef L_significandf
403WRAPPER1(significand)
404#endif