2 * Simple implementations of some C99 library functions.
3 * Note that the goal of altfloat is not to create a C99 math library: these
4 * functions are intended to just be "good enough" on platforms where they are
5 * missing. They likely do not fully conform to applicable standards.
7 * Copyright (C) 2010 Nick Bowler.
9 * License BSD2: 2-clause BSD license. See LICENSE for full terms.
10 * This is free software: you are free to change and redistribute it.
11 * There is NO WARRANTY, to the extent permitted by law.
18 double nan(const char *tagp
)
27 return log(x
) / log(2);
39 double fma(double x
, double y
, double z
)
41 return (long double) x
*y
+ z
;
46 double remquo(double x
, double y
, int *quo
)
48 unsigned tmp
= fabs(nearbyint(x
/y
));
49 int sign
= signbit(x
/y
) ? -1 : 1;
51 *quo
= sign
* (int)(tmp
% (INT_MAX
+ 1u));
52 return remainder(x
, y
);
57 * Float-valued functions implemented in terms of double-valued functions.
81 float atan2f(float x
, float y
)
109 float acoshf(float x
)
116 float asinhf(float x
)
123 float atanhf(float x
)
165 float expm1f(float x
)
172 float frexpf(float x
, int *exp
)
174 return frexp(x
, exp
);
186 float ldexpf(float x
, int exp
)
188 return ldexp(x
, exp
);
200 float log10f(float x
)
207 float log1pf(float x
)
228 float modff(float x
, float *iptr
)
238 #if NEED_LIBM_SCALBNF
239 float scalbnf(float x
, int exp
)
241 return scalbn(x
, exp
);
245 #if NEED_LIBM_SCALBLNF
246 float scalblnf(float x
, long exp
)
248 return scalbln(x
, exp
);
267 float hypotf(float x
, float y
)
274 float powf(float x
, float y
)
288 float fmodf(float x
, float y
)
294 #if NEED_LIBM_REMAINDERF
295 float remainderf(float x
, float y
)
297 return remainder(x
, y
);
301 #if NEED_LIBM_REMQUOF
302 float remquof(float x
, float y
, int *quo
)
304 return remquo(x
, y
, quo
);
308 #if NEED_LIBM_COPYSIGNF
309 float copysignf(float x
, float y
)
311 return copysign(x
, y
);
316 float nanf(const char *tagp
)
336 #if NEED_LIBM_LGAMMAF
337 float lgammaf(float x
)
343 #if NEED_LIBM_TGAMMAF
344 float tgammaf(float x
)
358 float floorf(float x
)
364 #if NEED_LIBM_NEARBYINTF
365 float nearbyintf(float x
)
385 #if NEED_LIBM_LLRINTF
386 long long llrintf(float x
)
393 float roundf(float x
)
399 #if NEED_LIBM_LROUNDF
400 long lroundf(float x
)
406 #if NEED_LIBM_LLRINTF
407 long long llroundf(float x
)
414 float truncf(float x
)
421 float fdimf(float x
, float y
)
428 float fmaxf(float x
, float y
)
435 float fminf(float x
, float y
)
442 float fmaf(float x
, float y
, float z
)