]>
git.ipfire.org Git - thirdparty/gcc.git/blob - libgfortran/intrinsics/c99_functions.c
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) floor(x
);
110 frexpf(float x
, int *exp
)
112 return (float) frexp(x
, exp
);
118 hypotf(float x
, float y
)
120 return (float) hypot(x
, y
);
128 return (float) log(x
);
136 return (float) log10(x
);
142 scalbnf(float x
, int y
)
144 return (float) scalbn(x
, y
);
152 return (float) sin(x
);
160 return (float) sinh(x
);
168 return (float) sqrt(x
);
176 return (float) tan(x
);
184 return (float) tanh(x
);
188 #ifndef HAVE_NEXTAFTERF
189 /* This is a portable implementation of nextafterf that is intended to be
190 independent of the floating point format or its in memory representation.
191 This implementation works correctly with denormalized values. */
193 nextafterf(float x
, float y
)
195 /* This variable is marked volatile to avoid excess precision problems
196 on some platforms, including IA-32. */
197 volatile float delta
;
198 float absx
, denorm_min
;
200 if (isnan(x
) || isnan(y
))
205 /* absx = fabsf (x); */
206 absx
= (x
< 0.0) ? -x
: x
;
208 /* __FLT_DENORM_MIN__ is non-zero iff the target supports denormals. */
209 if (__FLT_DENORM_MIN__
== 0.0f
)
210 denorm_min
= __FLT_MIN__
;
212 denorm_min
= __FLT_DENORM_MIN__
;
214 if (absx
< __FLT_MIN__
)
221 /* Discard the fraction from x. */
222 frac
= frexpf (absx
, &exp
);
223 delta
= scalbnf (0.5f
, exp
);
225 /* Scale x by the epsilon of the representation. By rights we should
226 have been able to combine this with scalbnf, but some targets don't
227 get that correct with denormals. */
228 delta
*= __FLT_EPSILON__
;
230 /* If we're going to be reducing the absolute value of X, and doing so
231 would reduce the exponent of X, then the delta to be applied is
232 one exponent smaller. */
233 if (frac
== 0.5f
&& (y
< x
) == (x
> 0))
236 /* If that underflows to zero, then we're back to the minimum. */
251 powf(float x
, float y
)
253 return (float) pow(x
, y
);
257 /* Note that if fpclassify is not defined, then NaN is not handled */
259 /* Algorithm by Steven G. Kargl. */
262 /* Round to nearest integral value. If the argument is halfway between two
263 integral values then round away from zero. */
269 #if defined(fpclassify)
272 if (i
== FP_INFINITE
|| i
== FP_NAN
)
294 /* Round to nearest integral value. If the argument is halfway between two
295 integral values then round away from zero. */
301 #if defined(fpclassify)
305 if (i
== FP_INFINITE
|| i
== FP_NAN
)