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 skips denormalized values, for example returning
192 FLT_MIN as the next value after zero, as many target's frexpf, scalbnf
193 and ldexpf functions don't work as expected with denormalized values. */
195 nextafterf(float x
, float y
)
199 if (isnan(x
) || isnan(y
))
205 return y
> 0.0f
? FLT_MIN
: -FLT_MIN
;
214 return x
+ scalbnf(FLT_EPSILON
, origexp
-1);
216 else if (x
> FLT_MIN
)
218 float temp
= x
- scalbnf(FLT_EPSILON
, origexp
-1);
219 frexpf(temp
, &newexp
);
220 if (newexp
== origexp
)
222 return x
- scalbnf(FLT_EPSILON
, origexp
-2);
233 return x
- scalbnf(FLT_EPSILON
, origexp
-1);
235 else if (x
< -FLT_MIN
)
237 float temp
= x
+ scalbnf(FLT_EPSILON
, origexp
-1);
238 frexpf(temp
, &newexp
);
239 if (newexp
== origexp
)
241 return x
+ scalbnf(FLT_EPSILON
, origexp
-2);
249 /* Note that if HAVE_FPCLASSIFY is not defined, then NaN is not handled */
251 /* Algorithm by Steven G. Kargl. */
254 /* Round to nearest integral value. If the argument is halfway between two
255 integral values then round away from zero. */
261 #ifdef HAVE_FPCLASSIFY
264 if (i
== FP_INFINITE
|| i
== FP_NAN
)
286 /* Round to nearest integral value. If the argument is halfway between two
287 integral values then round away from zero. */
293 #ifdef HAVE_FPCLASSIFY
297 if (i
== FP_INFINITE
|| i
== FP_NAN
)