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);
223 return (float) trunc (x);
227 #ifndef HAVE_NEXTAFTERF
228 /* This is a portable implementation of nextafterf that is intended to be
229 independent of the floating point format or its in memory representation.
230 This implementation works correctly with denormalized values. */
232 nextafterf(float x, float y)
234 /* This variable is marked volatile to avoid excess precision problems
235 on some platforms, including IA-32. */
236 volatile float delta;
237 float absx, denorm_min;
239 if (isnan(x) || isnan(y))
244 return x > 0 ? __FLT_MAX__ : - __FLT_MAX__;
246 /* absx = fabsf (x); */
247 absx = (x < 0.0) ? -x : x;
249 /* __FLT_DENORM_MIN__ is non-zero iff the target supports denormals. */
250 if (__FLT_DENORM_MIN__ == 0.0f)
251 denorm_min = __FLT_MIN__;
253 denorm_min = __FLT_DENORM_MIN__;
255 if (absx < __FLT_MIN__)
262 /* Discard the fraction from x. */
263 frac = frexpf (absx, &exp);
264 delta = scalbnf (0.5f, exp);
266 /* Scale x by the epsilon of the representation. By rights we should
267 have been able to combine this with scalbnf, but some targets don't
268 get that correct with denormals. */
269 delta *= __FLT_EPSILON__;
271 /* If we're going to be reducing the absolute value of X, and doing so
272 would reduce the exponent of X, then the delta to be applied is
273 one exponent smaller. */
274 if (frac == 0.5f && (y < x) == (x > 0))
277 /* If that underflows to zero, then we're back to the minimum. */
292 powf(float x, float y)
294 return (float) pow(x, y);
298 /* Note that if fpclassify is not defined, then NaN is not handled */
300 /* Algorithm by Steven G. Kargl. */
303 /* Round to nearest integral value. If the argument is halfway between two
304 integral values then round away from zero. */
310 #if defined(fpclassify)
313 if (i == FP_INFINITE || i == FP_NAN)
335 /* Round to nearest integral value. If the argument is halfway between two
336 integral values then round away from zero. */
342 #if defined(fpclassify)
346 if (i == FP_INFINITE || i == FP_NAN)