1 /* Implementation of various C99 functions
2 Copyright (C) 2004 Free Software Foundation, Inc.
4 This file is part of the GNU Fortran 95 runtime library (libgfortran).
6 Libgfortran is free software; you can redistribute it and/or
7 modify it under the terms of the GNU Lesser General Public
8 License as published by the Free Software Foundation; either
9 version 2.1 of the License, or (at your option) any later version.
11 Libgfortran is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU Lesser General Public License for more details.
16 You should have received a copy of the GNU Lesser General Public
17 License along with libgfortran; see the file COPYING.LIB. If not,
18 write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19 Boston, MA 02111-1307, USA. */
22 #include <sys/types.h>
25 #include "libgfortran.h"
32 return (float) acos(x
);
40 return (float) asin(x
);
46 atan2f(float y
, float x
)
48 return (float) atan2(y
, x
);
56 return (float) atan(x
);
64 return (float) ceil(x
);
68 #ifndef HAVE_COPYSIGNF
70 copysignf(float x
, float y
)
72 return (float) copysign(x
, y
);
80 return (float) cos(x
);
88 return (float) cosh(x
);
96 return (float) exp(x
);
104 return (float) fabs(x
);
112 return (float) floor(x
);
118 frexpf(float x
, int *exp
)
120 return (float) frexp(x
, exp
);
126 hypotf(float x
, float y
)
128 return (float) hypot(x
, y
);
136 return (float) log(x
);
144 return (float) log10(x
);
150 scalbnf(float x
, int y
)
152 return (float) scalbn(x
, y
);
160 return (float) sin(x
);
168 return (float) sinh(x
);
176 return (float) sqrt(x
);
184 return (float) tan(x
);
192 return (float) tanh(x
);
196 #ifndef HAVE_NEXTAFTERF
197 /* This is a portable implementation of nextafterf that is intended to be
198 independent of the floating point format or its in memory representation.
199 This implementation works correctly with denormalized values. */
201 nextafterf(float x
, float y
)
203 /* This variable is marked volatile to avoid excess precision problems
204 on some platforms, including IA-32. */
205 volatile float delta
;
206 float absx
, denorm_min
;
208 if (isnan(x
) || isnan(y
))
213 /* absx = fabsf (x); */
214 absx
= (x
< 0.0) ? -x
: x
;
216 /* __FLT_DENORM_MIN__ is non-zero iff the target supports denormals. */
217 if (__FLT_DENORM_MIN__
== 0.0f
)
218 denorm_min
= __FLT_MIN__
;
220 denorm_min
= __FLT_DENORM_MIN__
;
222 if (absx
< __FLT_MIN__
)
229 /* Discard the fraction from x. */
230 frac
= frexpf (absx
, &exp
);
231 delta
= scalbnf (0.5f
, exp
);
233 /* Scale x by the epsilon of the representation. By rights we should
234 have been able to combine this with scalbnf, but some targets don't
235 get that correct with denormals. */
236 delta
*= __FLT_EPSILON__
;
238 /* If we're going to be reducing the absolute value of X, and doing so
239 would reduce the exponent of X, then the delta to be applied is
240 one exponent smaller. */
241 if (frac
== 0.5f
&& (y
< x
) == (x
> 0))
244 /* If that underflows to zero, then we're back to the minimum. */
259 powf(float x
, float y
)
261 return (float) pow(x
, y
);
265 /* Note that if fpclassify is not defined, then NaN is not handled */
267 /* Algorithm by Steven G. Kargl. */
270 /* Round to nearest integral value. If the argument is halfway between two
271 integral values then round away from zero. */
277 #if defined(fpclassify)
280 if (i
== FP_INFINITE
|| i
== FP_NAN
)
302 /* Round to nearest integral value. If the argument is halfway between two
303 integral values then round away from zero. */
309 #if defined(fpclassify)
313 if (i
== FP_INFINITE
|| i
== FP_NAN
)