xref: /openbsd-src/gnu/gcc/libstdc++-v3/libmath/stubs.c (revision 404b540a9034ac75a6199ad1a32d1bbc7a0d4210)
1*404b540aSrobert /* Stub definitions for libmath subpart of libstdc++. */
2*404b540aSrobert 
3*404b540aSrobert /* Copyright (C) 2001, 2002, 2003 Free Software Foundation, Inc.
4*404b540aSrobert 
5*404b540aSrobert    This file is part of the GNU ISO C++ Library.  This library is free
6*404b540aSrobert    software; you can redistribute it and/or modify it under the
7*404b540aSrobert    terms of the GNU General Public License as published by the
8*404b540aSrobert    Free Software Foundation; either version 2, or (at your option)
9*404b540aSrobert    any later version.
10*404b540aSrobert 
11*404b540aSrobert    This library is distributed in the hope that it will be useful,
12*404b540aSrobert    but WITHOUT ANY WARRANTY; without even the implied warranty of
13*404b540aSrobert    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14*404b540aSrobert    GNU General Public License for more details.
15*404b540aSrobert 
16*404b540aSrobert    You should have received a copy of the GNU General Public License along
17*404b540aSrobert    with this library; see the file COPYING.  If not, write to the Free
18*404b540aSrobert    Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
19*404b540aSrobert    USA.
20*404b540aSrobert 
21*404b540aSrobert    As a special exception, you may use this file as part of a free software
22*404b540aSrobert    library without restriction.  Specifically, if other files instantiate
23*404b540aSrobert    templates or use macros or inline functions from this file, or you compile
24*404b540aSrobert    this file and link it with other files to produce an executable, this
25*404b540aSrobert    file does not by itself cause the resulting executable to be covered by
26*404b540aSrobert    the GNU General Public License.  This exception does not however
27*404b540aSrobert    invalidate any other reasons why the executable file might be covered by
28*404b540aSrobert    the GNU General Public License.  */
29*404b540aSrobert 
30*404b540aSrobert #include <math.h>
31*404b540aSrobert #include "config.h"
32*404b540aSrobert 
33*404b540aSrobert /* For targets which do not have support for long double versions,
34*404b540aSrobert    we use the crude approximation.  We'll do better later.  */
35*404b540aSrobert 
36*404b540aSrobert 
37*404b540aSrobert #ifndef HAVE_FABSF
38*404b540aSrobert float
fabsf(float x)39*404b540aSrobert fabsf(float x)
40*404b540aSrobert {
41*404b540aSrobert   return (float) fabs(x);
42*404b540aSrobert }
43*404b540aSrobert #endif
44*404b540aSrobert 
45*404b540aSrobert #ifndef HAVE_FABSL
46*404b540aSrobert long double
fabsl(long double x)47*404b540aSrobert fabsl(long double x)
48*404b540aSrobert {
49*404b540aSrobert   return fabs((double) x);
50*404b540aSrobert }
51*404b540aSrobert #endif
52*404b540aSrobert 
53*404b540aSrobert 
54*404b540aSrobert #ifndef HAVE_ACOSF
55*404b540aSrobert float
acosf(float x)56*404b540aSrobert acosf(float x)
57*404b540aSrobert {
58*404b540aSrobert   return (float) acos(x);
59*404b540aSrobert }
60*404b540aSrobert #endif
61*404b540aSrobert 
62*404b540aSrobert #ifndef HAVE_ACOSL
63*404b540aSrobert long double
acosl(long double x)64*404b540aSrobert acosl(long double x)
65*404b540aSrobert {
66*404b540aSrobert   return acos((double) x);
67*404b540aSrobert }
68*404b540aSrobert #endif
69*404b540aSrobert 
70*404b540aSrobert 
71*404b540aSrobert #ifndef HAVE_ASINF
72*404b540aSrobert float
asinf(float x)73*404b540aSrobert asinf(float x)
74*404b540aSrobert {
75*404b540aSrobert   return (float) asin(x);
76*404b540aSrobert }
77*404b540aSrobert #endif
78*404b540aSrobert 
79*404b540aSrobert #ifndef HAVE_ASINL
80*404b540aSrobert long double
asinl(long double x)81*404b540aSrobert asinl(long double x)
82*404b540aSrobert {
83*404b540aSrobert   return asin((double) x);
84*404b540aSrobert }
85*404b540aSrobert #endif
86*404b540aSrobert 
87*404b540aSrobert 
88*404b540aSrobert #ifndef HAVE_ATANF
89*404b540aSrobert float
atanf(float x)90*404b540aSrobert atanf(float x)
91*404b540aSrobert {
92*404b540aSrobert   return (float) atan(x);
93*404b540aSrobert }
94*404b540aSrobert #endif
95*404b540aSrobert 
96*404b540aSrobert #ifndef HAVE_ATANL
97*404b540aSrobert long double
atanl(long double x)98*404b540aSrobert atanl(long double x)
99*404b540aSrobert {
100*404b540aSrobert   return atan ((double) x);
101*404b540aSrobert }
102*404b540aSrobert #endif
103*404b540aSrobert 
104*404b540aSrobert 
105*404b540aSrobert #ifndef HAVE_ATAN2F
106*404b540aSrobert float
atan2f(float x,float y)107*404b540aSrobert atan2f(float x, float y)
108*404b540aSrobert {
109*404b540aSrobert   return (float) atan2(x, y);
110*404b540aSrobert }
111*404b540aSrobert #endif
112*404b540aSrobert 
113*404b540aSrobert #ifndef HAVE_ATAN2L
114*404b540aSrobert long double
atan2l(long double x,long double y)115*404b540aSrobert atan2l(long double x, long double y)
116*404b540aSrobert {
117*404b540aSrobert   return atan2((double) x, (double) y);
118*404b540aSrobert }
119*404b540aSrobert #endif
120*404b540aSrobert 
121*404b540aSrobert 
122*404b540aSrobert #ifndef HAVE_CEILF
123*404b540aSrobert float
ceilf(float x)124*404b540aSrobert ceilf(float x)
125*404b540aSrobert {
126*404b540aSrobert   return (float) ceil(x);
127*404b540aSrobert }
128*404b540aSrobert #endif
129*404b540aSrobert 
130*404b540aSrobert #ifndef HAVE_CEILL
131*404b540aSrobert long double
ceill(long double x)132*404b540aSrobert ceill(long double x)
133*404b540aSrobert {
134*404b540aSrobert   return ceil((double) x);
135*404b540aSrobert }
136*404b540aSrobert #endif
137*404b540aSrobert 
138*404b540aSrobert 
139*404b540aSrobert #ifndef HAVE_COSF
140*404b540aSrobert float
cosf(float x)141*404b540aSrobert cosf(float x)
142*404b540aSrobert {
143*404b540aSrobert   return (float) cos(x);
144*404b540aSrobert }
145*404b540aSrobert #endif
146*404b540aSrobert 
147*404b540aSrobert #ifndef HAVE_COSL
148*404b540aSrobert long double
cosl(long double x)149*404b540aSrobert cosl(long double x)
150*404b540aSrobert {
151*404b540aSrobert   return cos((double) x);
152*404b540aSrobert }
153*404b540aSrobert #endif
154*404b540aSrobert 
155*404b540aSrobert 
156*404b540aSrobert #ifndef HAVE_COSHF
157*404b540aSrobert float
coshf(float x)158*404b540aSrobert coshf(float x)
159*404b540aSrobert {
160*404b540aSrobert   return (float) cosh(x);
161*404b540aSrobert }
162*404b540aSrobert #endif
163*404b540aSrobert 
164*404b540aSrobert #ifndef HAVE_COSHL
165*404b540aSrobert long double
coshl(long double x)166*404b540aSrobert coshl(long double x)
167*404b540aSrobert {
168*404b540aSrobert   return cosh((double) x);
169*404b540aSrobert }
170*404b540aSrobert #endif
171*404b540aSrobert 
172*404b540aSrobert 
173*404b540aSrobert #ifndef HAVE_EXPF
174*404b540aSrobert float
expf(float x)175*404b540aSrobert expf(float x)
176*404b540aSrobert {
177*404b540aSrobert   return (float) exp(x);
178*404b540aSrobert }
179*404b540aSrobert #endif
180*404b540aSrobert 
181*404b540aSrobert #ifndef HAVE_EXPL
182*404b540aSrobert long double
expl(long double x)183*404b540aSrobert expl(long double x)
184*404b540aSrobert {
185*404b540aSrobert   return exp((double) x);
186*404b540aSrobert }
187*404b540aSrobert #endif
188*404b540aSrobert 
189*404b540aSrobert 
190*404b540aSrobert #ifndef HAVE_FLOORF
191*404b540aSrobert float
floorf(float x)192*404b540aSrobert floorf(float x)
193*404b540aSrobert {
194*404b540aSrobert   return (float) floor(x);
195*404b540aSrobert }
196*404b540aSrobert #endif
197*404b540aSrobert 
198*404b540aSrobert #ifndef HAVE_FLOORL
199*404b540aSrobert long double
floorl(long double x)200*404b540aSrobert floorl(long double x)
201*404b540aSrobert {
202*404b540aSrobert   return floor((double) x);
203*404b540aSrobert }
204*404b540aSrobert #endif
205*404b540aSrobert 
206*404b540aSrobert 
207*404b540aSrobert #ifndef HAVE_FMODF
208*404b540aSrobert float
fmodf(float x,float y)209*404b540aSrobert fmodf(float x, float y)
210*404b540aSrobert {
211*404b540aSrobert   return (float) fmod(x, y);
212*404b540aSrobert }
213*404b540aSrobert #endif
214*404b540aSrobert 
215*404b540aSrobert #ifndef HAVE_FMODL
216*404b540aSrobert long double
fmodl(long double x,long double y)217*404b540aSrobert fmodl(long double x, long double y)
218*404b540aSrobert {
219*404b540aSrobert   return fmod((double) x, (double) y);
220*404b540aSrobert }
221*404b540aSrobert #endif
222*404b540aSrobert 
223*404b540aSrobert 
224*404b540aSrobert #ifndef HAVE_FREXPF
225*404b540aSrobert float
frexpf(float x,int * exp)226*404b540aSrobert frexpf(float x, int *exp)
227*404b540aSrobert {
228*404b540aSrobert   return (float) frexp(x, exp);
229*404b540aSrobert }
230*404b540aSrobert #endif
231*404b540aSrobert 
232*404b540aSrobert #ifndef HAVE_FREXPL
233*404b540aSrobert long double
frexpl(long double x,int * exp)234*404b540aSrobert frexpl(long double x, int *exp)
235*404b540aSrobert {
236*404b540aSrobert   return frexp((double) x, exp);
237*404b540aSrobert }
238*404b540aSrobert #endif
239*404b540aSrobert 
240*404b540aSrobert 
241*404b540aSrobert #ifndef HAVE_SQRTF
242*404b540aSrobert float
sqrtf(float x)243*404b540aSrobert sqrtf(float x)
244*404b540aSrobert {
245*404b540aSrobert   return (float) sqrt(x);
246*404b540aSrobert }
247*404b540aSrobert #endif
248*404b540aSrobert 
249*404b540aSrobert #ifndef HAVE_SQRTL
250*404b540aSrobert long double
sqrtl(long double x)251*404b540aSrobert sqrtl(long double x)
252*404b540aSrobert {
253*404b540aSrobert   return  sqrt((double) x);
254*404b540aSrobert }
255*404b540aSrobert #endif
256*404b540aSrobert 
257*404b540aSrobert 
258*404b540aSrobert /* Compute the hypothenuse of a right triangle with side x and y.  */
259*404b540aSrobert #ifndef HAVE_HYPOTF
260*404b540aSrobert float
hypotf(float x,float y)261*404b540aSrobert hypotf(float x, float y)
262*404b540aSrobert {
263*404b540aSrobert   float s = fabsf(x) + fabsf(y);
264*404b540aSrobert   if (s == 0.0F)
265*404b540aSrobert     return s;
266*404b540aSrobert   x /= s; y /= s;
267*404b540aSrobert   return s * sqrtf(x * x + y * y);
268*404b540aSrobert }
269*404b540aSrobert #endif
270*404b540aSrobert 
271*404b540aSrobert #ifndef HAVE_HYPOT
272*404b540aSrobert double
hypot(double x,double y)273*404b540aSrobert hypot(double x, double y)
274*404b540aSrobert {
275*404b540aSrobert   double s = fabs(x) + fabs(y);
276*404b540aSrobert   if (s == 0.0)
277*404b540aSrobert     return s;
278*404b540aSrobert   x /= s; y /= s;
279*404b540aSrobert   return s * sqrt(x * x + y * y);
280*404b540aSrobert }
281*404b540aSrobert #endif
282*404b540aSrobert 
283*404b540aSrobert #ifndef HAVE_HYPOTL
284*404b540aSrobert long double
hypotl(long double x,long double y)285*404b540aSrobert hypotl(long double x, long double y)
286*404b540aSrobert {
287*404b540aSrobert   long double s = fabsl(x) + fabsl(y);
288*404b540aSrobert   if (s == 0.0L)
289*404b540aSrobert     return s;
290*404b540aSrobert   x /= s; y /= s;
291*404b540aSrobert   return s * sqrtl(x * x + y * y);
292*404b540aSrobert }
293*404b540aSrobert #endif
294*404b540aSrobert 
295*404b540aSrobert 
296*404b540aSrobert 
297*404b540aSrobert #ifndef HAVE_LDEXPF
298*404b540aSrobert float
ldexpf(float x,int exp)299*404b540aSrobert ldexpf(float x, int exp)
300*404b540aSrobert {
301*404b540aSrobert   return (float) ldexp(x, exp);
302*404b540aSrobert }
303*404b540aSrobert #endif
304*404b540aSrobert 
305*404b540aSrobert #ifndef HAVE_LDEXPL
306*404b540aSrobert long double
ldexpl(long double x,int exp)307*404b540aSrobert ldexpl(long double x, int exp)
308*404b540aSrobert {
309*404b540aSrobert   return ldexp((double) x, exp);
310*404b540aSrobert }
311*404b540aSrobert #endif
312*404b540aSrobert 
313*404b540aSrobert 
314*404b540aSrobert #ifndef HAVE_LOGF
315*404b540aSrobert float
logf(float x)316*404b540aSrobert logf(float x)
317*404b540aSrobert {
318*404b540aSrobert   return (float) log(x);
319*404b540aSrobert }
320*404b540aSrobert #endif
321*404b540aSrobert 
322*404b540aSrobert #ifndef HAVE_LOGL
323*404b540aSrobert long double
logl(long double x)324*404b540aSrobert logl(long double x)
325*404b540aSrobert {
326*404b540aSrobert   return log((double) x);
327*404b540aSrobert }
328*404b540aSrobert #endif
329*404b540aSrobert 
330*404b540aSrobert 
331*404b540aSrobert #ifndef HAVE_LOG10F
332*404b540aSrobert float
log10f(float x)333*404b540aSrobert log10f(float x)
334*404b540aSrobert {
335*404b540aSrobert   return (float) log10(x);
336*404b540aSrobert }
337*404b540aSrobert #endif
338*404b540aSrobert 
339*404b540aSrobert #ifndef HAVE_LOG10L
340*404b540aSrobert long double
log10l(long double x)341*404b540aSrobert log10l(long double x)
342*404b540aSrobert {
343*404b540aSrobert   return log10((double) x);
344*404b540aSrobert }
345*404b540aSrobert #endif
346*404b540aSrobert 
347*404b540aSrobert 
348*404b540aSrobert #ifndef HAVE_MODFF
349*404b540aSrobert float
modff(float x,float * iptr)350*404b540aSrobert modff(float x, float *iptr)
351*404b540aSrobert {
352*404b540aSrobert   double result, temp;
353*404b540aSrobert 
354*404b540aSrobert   result = modf(x, &temp);
355*404b540aSrobert   *iptr = (float) temp;
356*404b540aSrobert   return (float) result;
357*404b540aSrobert }
358*404b540aSrobert #endif
359*404b540aSrobert 
360*404b540aSrobert #ifndef HAVE_MODFL
361*404b540aSrobert long double
modfl(long double x,long double * iptr)362*404b540aSrobert modfl(long double x, long double *iptr)
363*404b540aSrobert {
364*404b540aSrobert   double result, temp;
365*404b540aSrobert 
366*404b540aSrobert   result = modf((double) x, &temp);
367*404b540aSrobert   *iptr = temp;
368*404b540aSrobert   return result;
369*404b540aSrobert }
370*404b540aSrobert #endif
371*404b540aSrobert 
372*404b540aSrobert 
373*404b540aSrobert #ifndef HAVE_POWF
374*404b540aSrobert float
powf(float x,float y)375*404b540aSrobert powf(float x, float y)
376*404b540aSrobert {
377*404b540aSrobert   return (float) pow(x, y);
378*404b540aSrobert }
379*404b540aSrobert #endif
380*404b540aSrobert 
381*404b540aSrobert #ifndef HAVE_POWL
382*404b540aSrobert long double
powl(long double x,long double y)383*404b540aSrobert powl(long double x, long double y)
384*404b540aSrobert {
385*404b540aSrobert   return pow((double) x, (double) y);
386*404b540aSrobert }
387*404b540aSrobert #endif
388*404b540aSrobert 
389*404b540aSrobert 
390*404b540aSrobert #ifndef HAVE_SINF
391*404b540aSrobert float
sinf(float x)392*404b540aSrobert sinf(float x)
393*404b540aSrobert {
394*404b540aSrobert   return (float) sin(x);
395*404b540aSrobert }
396*404b540aSrobert #endif
397*404b540aSrobert 
398*404b540aSrobert #ifndef HAVE_SINL
399*404b540aSrobert long double
sinl(long double x)400*404b540aSrobert sinl(long double x)
401*404b540aSrobert {
402*404b540aSrobert   return sin((double) x);
403*404b540aSrobert }
404*404b540aSrobert #endif
405*404b540aSrobert 
406*404b540aSrobert 
407*404b540aSrobert #ifndef HAVE_SINHF
408*404b540aSrobert float
sinhf(float x)409*404b540aSrobert sinhf(float x)
410*404b540aSrobert {
411*404b540aSrobert   return (float) sinh(x);
412*404b540aSrobert }
413*404b540aSrobert #endif
414*404b540aSrobert 
415*404b540aSrobert #ifndef HAVE_SINHL
416*404b540aSrobert long double
sinhl(long double x)417*404b540aSrobert sinhl(long double x)
418*404b540aSrobert {
419*404b540aSrobert   return sinh((double) x);
420*404b540aSrobert }
421*404b540aSrobert #endif
422*404b540aSrobert 
423*404b540aSrobert 
424*404b540aSrobert #ifndef HAVE_TANF
425*404b540aSrobert float
tanf(float x)426*404b540aSrobert tanf(float x)
427*404b540aSrobert {
428*404b540aSrobert   return (float) tan(x);
429*404b540aSrobert }
430*404b540aSrobert #endif
431*404b540aSrobert 
432*404b540aSrobert #ifndef HAVE_TANL
433*404b540aSrobert long double
tanl(long double x)434*404b540aSrobert tanl(long double x)
435*404b540aSrobert {
436*404b540aSrobert   return tan((double) x);
437*404b540aSrobert }
438*404b540aSrobert #endif
439*404b540aSrobert 
440*404b540aSrobert 
441*404b540aSrobert #ifndef HAVE_TANHF
442*404b540aSrobert float
tanhf(float x)443*404b540aSrobert tanhf(float x)
444*404b540aSrobert {
445*404b540aSrobert   return (float) tanh(x);
446*404b540aSrobert }
447*404b540aSrobert #endif
448*404b540aSrobert 
449*404b540aSrobert #ifndef HAVE_TANHL
450*404b540aSrobert long double
tanhl(long double x)451*404b540aSrobert tanhl(long double x)
452*404b540aSrobert {
453*404b540aSrobert   return tanh((double) x);
454*404b540aSrobert }
455*404b540aSrobert #endif
456