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 General Public
8 License as published by the Free Software Foundation; either
9 version 2 of the License, or (at your option) any later version.
11 In addition to the permissions in the GNU General Public License, the
12 Free Software Foundation gives you unlimited permission to link the
13 compiled version of this file into combinations with other programs,
14 and to distribute those combinations without any restriction coming
15 from the use of this file. (The General Public License restrictions
16 do apply in other respects; for example, they cover modification of
17 the file, and distribution when not linked into a combine
20 Libgfortran is distributed in the hope that it will be useful,
21 but WITHOUT ANY WARRANTY; without even the implied warranty of
22 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 GNU General Public License for more details.
25 You should have received a copy of the GNU General Public
26 License along with libgfortran; see the file COPYING. If not,
27 write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
28 Boston, MA 02111-1307, USA. */
31 #include <sys/types.h>
34 #include "libgfortran.h"
41 return (float) acos(x);
49 return (float) asin(x);
55 atan2f(float y, float x)
57 return (float) atan2(y, x);
65 return (float) atan(x);
73 return (float) ceil(x);
77 #ifndef HAVE_COPYSIGNF
79 copysignf(float x, float y)
81 return (float) copysign(x, y);
89 return (float) cos(x);
97 return (float) cosh(x);
105 return (float) exp(x);
113 return (float) fabs(x);
121 return (float) floor(x);
127 frexpf(float x, int *exp)
129 return (float) frexp(x, exp);
135 hypotf(float x, float y)
137 return (float) hypot(x, y);
145 return (float) log(x);
153 return (float) log10(x);
159 scalbnf(float x, int y)
161 return (float) scalbn(x, y);
169 return (float) sin(x);
177 return (float) sinh(x);
185 return (float) sqrt(x);
193 return (float) tan(x);
201 return (float) tanh(x);
205 #ifndef HAVE_NEXTAFTERF
206 /* This is a portable implementation of nextafterf that is intended to be
207 independent of the floating point format or its in memory representation.
208 This implementation works correctly with denormalized values. */
210 nextafterf(float x, float y)
212 /* This variable is marked volatile to avoid excess precision problems
213 on some platforms, including IA-32. */
214 volatile float delta;
215 float absx, denorm_min;
217 if (isnan(x) || isnan(y))
222 return x > 0 ? __FLT_MAX__ : - __FLT_MAX__;
224 /* absx = fabsf (x); */
225 absx = (x < 0.0) ? -x : x;
227 /* __FLT_DENORM_MIN__ is non-zero iff the target supports denormals. */
228 if (__FLT_DENORM_MIN__ == 0.0f)
229 denorm_min = __FLT_MIN__;
231 denorm_min = __FLT_DENORM_MIN__;
233 if (absx < __FLT_MIN__)
240 /* Discard the fraction from x. */
241 frac = frexpf (absx, &exp);
242 delta = scalbnf (0.5f, exp);
244 /* Scale x by the epsilon of the representation. By rights we should
245 have been able to combine this with scalbnf, but some targets don't
246 get that correct with denormals. */
247 delta *= __FLT_EPSILON__;
249 /* If we're going to be reducing the absolute value of X, and doing so
250 would reduce the exponent of X, then the delta to be applied is
251 one exponent smaller. */
252 if (frac == 0.5f && (y < x) == (x > 0))
255 /* If that underflows to zero, then we're back to the minimum. */
270 powf(float x, float y)
272 return (float) pow(x, y);
276 /* Note that if fpclassify is not defined, then NaN is not handled */
278 /* Algorithm by Steven G. Kargl. */
281 /* Round to nearest integral value. If the argument is halfway between two
282 integral values then round away from zero. */
288 #if defined(fpclassify)
291 if (i == FP_INFINITE || i == FP_NAN)
313 /* Round to nearest integral value. If the argument is halfway between two
314 integral values then round away from zero. */
320 #if defined(fpclassify)
324 if (i == FP_INFINITE || i == FP_NAN)