blob: 118a78f647cfeee3cf2f0877d95aa70a7dac5fa0 [file] [log] [blame]
yuezonghe824eb0c2024-06-27 02:32:26 -07001/* vi: set sw=4 ts=4: */
2/*
3 * Wrapper functions implementing all the long double math functions
4 * defined by SuSv3 by actually calling the double version of
5 * each function and then casting the result back to a long double
6 * to return to the user.
7 *
8 * Copyright (C) 2005 by Erik Andersen <andersen@uclibc.org>
9 *
10 * Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
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#define WRAPPER1(func) \
20long double func##l(long double x) \
21{ \
22 return (long double) func((double) x); \
23}
24#define WRAPPER2(func) \
25long double func##l(long double x, long double y) \
26{ \
27 return (long double) func((double) x, (double) y); \
28}
29#define int_WRAPPER1(func) \
30int func##l(long double x) \
31{ \
32 return func((double) x); \
33}
34#define long_WRAPPER1(func) \
35long func##l(long double x) \
36{ \
37 return func((double) x); \
38}
39#define long_long_WRAPPER1(func) \
40long long func##l(long double x) \
41{ \
42 return func((double) x); \
43}
44
45/* Implement the following, as defined by SuSv3 */
46#if 0
47long double acoshl(long double);
48long double acosl(long double);
49long double asinhl(long double);
50long double asinl(long double);
51long double atan2l(long double, long double);
52long double atanhl(long double);
53long double atanl(long double);
54long double cargl(long double complex);
55long double cbrtl(long double);
56long double ceill(long double);
57long double copysignl(long double, long double);
58long double coshl(long double);
59long double cosl(long double);
60long double erfcl(long double);
61long double erfl(long double);
62long double exp2l(long double);
63long double expl(long double);
64long double expm1l(long double);
65long double fabsl(long double);
66long double fdiml(long double, long double);
67long double floorl(long double);
68long double fmal(long double, long double, long double);
69long double fmaxl(long double, long double);
70long double fminl(long double, long double);
71long double fmodl(long double, long double);
72long double frexpl(long double value, int *);
73long double hypotl(long double, long double);
74int ilogbl(long double);
75long double ldexpl(long double, int);
76long double lgammal(long double);
77long long llrintl(long double);
78long long llroundl(long double);
79long double log10l(long double);
80long double log1pl(long double);
81long double log2l(long double);
82long double logbl(long double);
83long double logl(long double);
84long lrintl(long double);
85long lroundl(long double);
86long double modfl(long double, long double *);
87long double nearbyintl(long double);
88long double nextafterl(long double, long double);
89long double nexttowardl(long double, long double);
90long double powl(long double, long double);
91long double remainderl(long double, long double);
92long double remquol(long double, long double, int *);
93long double rintl(long double);
94long double roundl(long double);
95long double scalblnl(long double, long);
96long double scalbnl(long double, int);
97long double sinhl(long double);
98long double sinl(long double);
99long double sqrtl(long double);
100long double tanhl(long double);
101long double tanl(long double);
102long double tgammal(long double);
103long double truncl(long double);
104#endif
105
106#ifdef L_acoshl
107WRAPPER1(acosh)
108#endif
109
110#ifdef L_acosl
111WRAPPER1(acos)
112#endif
113
114#ifdef L_asinhl
115WRAPPER1(asinh)
116#endif
117
118#ifdef L_asinl
119WRAPPER1(asin)
120#endif
121
122#ifdef L_atan2l
123WRAPPER2(atan2)
124#endif
125
126#ifdef L_atanhl
127WRAPPER1(atanh)
128#endif
129
130#ifdef L_atanl
131WRAPPER1(atan)
132#endif
133
134#ifdef L_cargl
135long double cargl (long double complex x)
136{
137 return (long double) carg( (double complex)x );
138}
139#endif
140
141#ifdef L_cbrtl
142WRAPPER1(cbrt)
143#endif
144
145#ifdef L_ceill
146WRAPPER1(ceil)
147#endif
148
149#ifdef L_copysignl
150WRAPPER2(copysign)
151#endif
152
153#ifdef L_coshl
154WRAPPER1(cosh)
155#endif
156
157#ifdef L_cosl
158WRAPPER1(cos)
159#endif
160
161#ifdef L_erfcl
162WRAPPER1(erfc)
163#endif
164
165#ifdef L_erfl
166WRAPPER1(erf)
167#endif
168
169#ifdef L_exp2l
170WRAPPER1(exp2)
171#endif
172
173#ifdef L_expl
174WRAPPER1(exp)
175#endif
176
177#ifdef L_expm1l
178WRAPPER1(expm1)
179#endif
180
181#ifdef L_fabsl
182WRAPPER1(fabs)
183#endif
184
185#ifdef L_fdiml
186WRAPPER2(fdim)
187#endif
188
189#ifdef L_floorl
190WRAPPER1(floor)
191#endif
192
193#ifdef L_fmal
194long double fmal (long double x, long double y, long double z)
195{
196 return (long double) fma( (double)x, (double)y, (double)z );
197}
198#endif
199
200#ifdef L_fmaxl
201WRAPPER2(fmax)
202#endif
203
204#ifdef L_fminl
205WRAPPER2(fmin)
206#endif
207
208#ifdef L_fmodl
209WRAPPER2(fmod)
210#endif
211
212#ifdef L_frexpl
213long double frexpl (long double x, int *ex)
214{
215 return (long double) frexp( (double)x, ex );
216}
217#endif
218
219#ifdef L_gammal
220WRAPPER1(gamma)
221#endif
222
223#ifdef L_hypotl
224WRAPPER2(hypot)
225#endif
226
227#ifdef L_ilogbl
228int_WRAPPER1(ilogb)
229#endif
230
231#ifdef L_ldexpl
232long double ldexpl (long double x, int ex)
233{
234 return (long double) ldexp( (double)x, ex );
235}
236#endif
237
238#ifdef L_lgammal
239WRAPPER1(lgamma)
240#endif
241
242#ifdef L_llrintl
243long_long_WRAPPER1(llrint)
244#endif
245
246#ifdef L_llroundl
247long_long_WRAPPER1(llround)
248#endif
249
250#ifdef L_log10l
251WRAPPER1(log10)
252#endif
253
254#ifdef L_log1pl
255WRAPPER1(log1p)
256#endif
257
258#ifdef L_log2l
259WRAPPER1(log2)
260#endif
261
262#ifdef L_logbl
263WRAPPER1(logb)
264#endif
265
266#ifdef L_logl
267WRAPPER1(log)
268#endif
269
270#ifdef L_lrintl
271long_WRAPPER1(lrint)
272#endif
273
274#ifdef L_lroundl
275long_WRAPPER1(lround)
276#endif
277
278#ifdef L_modfl
279long double modfl (long double x, long double *iptr)
280{
281 double y, result;
282 result = modf ( x, &y );
283 *iptr = (long double)y;
284 return (long double) result;
285}
286#endif
287
288#ifdef L_nearbyintl
289WRAPPER1(nearbyint)
290#endif
291
292#ifdef L_nextafterl
293WRAPPER2(nextafter)
294#endif
295
296/* Disabled in Makefile.in */
297#if 0 /* def L_nexttowardl */
298WRAPPER2(nexttoward)
299libm_hidden_def(nexttowardl)
300#endif
301
302#ifdef L_powl
303WRAPPER2(pow)
304#endif
305
306#ifdef L_remainderl
307WRAPPER2(remainder)
308#endif
309
310#ifdef L_remquol
311long double remquol (long double x, long double y, int *quo)
312{
313 return (long double) remquo( (double)x, (double)y, quo );
314}
315#endif
316
317#ifdef L_rintl
318WRAPPER1(rint)
319#endif
320
321#ifdef L_roundl
322WRAPPER1(round)
323#endif
324
325#ifdef L_scalblnl
326long double scalblnl (long double x, long ex)
327{
328 return (long double) scalbln( (double)x, ex );
329}
330#endif
331
332#ifdef L_scalbnl
333long double scalbnl (long double x, int ex)
334{
335 return (long double) scalbn( (double)x, ex );
336}
337#endif
338
339/* scalb is an obsolete function */
340
341#ifdef L_sinhl
342WRAPPER1(sinh)
343#endif
344
345#ifdef L_sinl
346WRAPPER1(sin)
347#endif
348
349#ifdef L_sqrtl
350WRAPPER1(sqrt)
351#endif
352
353#ifdef L_tanhl
354WRAPPER1(tanh)
355#endif
356
357#ifdef L_tanl
358WRAPPER1(tan)
359#endif
360
361#ifdef L_tgammal
362WRAPPER1(tgamma)
363#endif
364
365#ifdef L_truncl
366WRAPPER1(trunc)
367#endif
368
369#ifdef L_significandl
370WRAPPER1(significand)
371#endif
372
373#if defined __DO_C99_MATH__ && !defined __NO_LONG_DOUBLE_MATH
374
375# ifdef L___fpclassifyl
376int_WRAPPER1(__fpclassify)
377libm_hidden_def(__fpclassifyl)
378# endif
379
380# ifdef L___finitel
381int_WRAPPER1(__finite)
382libm_hidden_def(__finitel)
383# endif
384
385# ifdef L___signbitl
386int_WRAPPER1(__signbit)
387libm_hidden_def(__signbitl)
388# endif
389
390# ifdef L___isnanl
391int_WRAPPER1(__isnan)
392libm_hidden_def(__isnanl)
393# endif
394
395# ifdef L___isinfl
396int_WRAPPER1(__isinf)
397libm_hidden_def(__isinfl)
398# endif
399
400#endif