cmath: Fix bad typo in atan2 and atan2f.
[altfloat.git] / c99-compat.c
blob51e7661204b315cf1a0e0141aa9fbdbc597e5130
1 /*
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.
13 #include <config.h>
14 #include <limits.h>
15 #include <math.h>
17 #if NEED_LIBM_NAN
18 double nan(const char *tagp)
20 return NAN;
22 #endif
24 #if NEED_LIBM_LOG2
25 double log2(double x)
27 return log(x) / log(2);
29 #endif
31 #if NEED_LIBM_EXP2
32 double exp2(double x)
34 return pow(2, x);
36 #endif
38 #if NEED_LIBM_FMA
39 double fma(double x, double y, double z)
41 return (long double) x*y + z;
43 #endif
45 #if NEED_LIBM_REMQUO
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);
54 #endif
57 * Float-valued functions implemented in terms of double-valued functions.
59 #if NEED_LIBM_ACOSF
60 float acosf(float x)
62 return acos(x);
64 #endif
66 #if NEED_LIBM_ASINF
67 float asinf(float x)
69 return asin(x);
71 #endif
73 #if NEED_LIBM_ATANF
74 float atanf(float x)
76 return atan(x);
78 #endif
80 #if NEED_LIBM_ATAN2F
81 float atan2f(float x, float y)
83 return atan2(x, y);
85 #endif
87 #if NEED_LIBM_COSF
88 float cosf(float x)
90 return cos(x);
92 #endif
94 #if NEED_LIBM_SINF
95 float sinf(float x)
97 return sin(x);
99 #endif
101 #if NEED_LIBM_TANF
102 float tanf(float x)
104 return tan(x);
106 #endif
108 #if NEED_LIBM_ACOSHF
109 float acoshf(float x)
111 return acosh(x);
113 #endif
115 #if NEED_LIBM_ASINHF
116 float asinhf(float x)
118 return asinh(x);
120 #endif
122 #if NEED_LIBM_ATANHF
123 float atanhf(float x)
125 return atanh(x);
127 #endif
129 #if NEED_LIBM_COSHF
130 float coshf(float x)
132 return cosh(x);
134 #endif
136 #if NEED_LIBM_SINHF
137 float sinhf(float x)
139 return sinh(x);
141 #endif
143 #if NEED_LIBM_TANHF
144 float tanhf(float x)
146 return tanh(x);
148 #endif
150 #if NEED_LIBM_EXPF
151 float expf(float x)
153 return exp(x);
155 #endif
157 #if NEED_LIBM_EXP2F
158 float exp2f(float x)
160 return exp2(x);
162 #endif
164 #if NEED_LIBM_EXPM1F
165 float expm1f(float x)
167 return expm1(x);
169 #endif
171 #if NEED_LIBM_FREXPF
172 float frexpf(float x, int *exp)
174 return frexp(x, exp);
176 #endif
178 #if NEED_LIBM_ILOGBF
179 int ilogbf(float x)
181 return ilogb(x);
183 #endif
185 #if NEED_LIBM_LDEXPF
186 float ldexpf(float x, int exp)
188 return ldexp(x, exp);
190 #endif
192 #if NEED_LIBM_LOGF
193 float logf(float x)
195 return log(x);
197 #endif
199 #if NEED_LIBM_LOG10F
200 float log10f(float x)
202 return log10(x);
204 #endif
206 #if NEED_LIBM_LOG1PF
207 float log1pf(float x)
209 return log1p(x);
211 #endif
213 #if NEED_LIBM_LOG2F
214 float log2f(float x)
216 return log2(x);
218 #endif
220 #if NEED_LIBM_LOGBF
221 float logbf(float x)
223 return logb(x);
225 #endif
227 #if NEED_LIBM_MODFF
228 float modff(float x, float *iptr)
230 double tmp, ret;
232 ret = modf(x, &tmp);
233 *iptr = tmp;
234 return ret;
236 #endif
238 #if NEED_LIBM_SCALBNF
239 float scalbnf(float x, int exp)
241 return scalbn(x, exp);
243 #endif
245 #if NEED_LIBM_SCALBLNF
246 float scalblnf(float x, long exp)
248 return scalbln(x, exp);
250 #endif
252 #if NEED_LIBM_CBRTF
253 float cbrtf(float x)
255 return cbrt(x);
257 #endif
259 #if NEED_LIBM_FABSF
260 float fabsf(float x)
262 return fabs(x);
264 #endif
266 #if NEED_LIBM_HYPOTF
267 float hypotf(float x, float y)
269 return hypot(x, y);
271 #endif
273 #if NEED_LIBM_POWF
274 float powf(float x, float y)
276 return pow(x, y);
278 #endif
280 #if NEED_LIBM_SQRTF
281 float sqrtf(float x)
283 return sqrt(x);
285 #endif
287 #if NEED_LIBM_FMODF
288 float fmodf(float x, float y)
290 return fmod(x, y);
292 #endif
294 #if NEED_LIBM_REMAINDERF
295 float remainderf(float x, float y)
297 return remainder(x, y);
299 #endif
301 #if NEED_LIBM_REMQUOF
302 float remquof(float x, float y, int *quo)
304 return remquo(x, y, quo);
306 #endif
308 #if NEED_LIBM_COPYSIGNF
309 float copysignf(float x, float y)
311 return copysign(x, y);
313 #endif
315 #if NEED_LIBM_NANF
316 float nanf(const char *tagp)
318 return nan(tagp);
320 #endif
322 #if NEED_LIBM_ERFF
323 float erff(float x)
325 return erf(x);
327 #endif
329 #if NEED_LIBM_ERFCF
330 float erfcf(float x)
332 return erfc(x);
334 #endif
336 #if NEED_LIBM_LGAMMAF
337 float lgammaf(float x)
339 return lgamma(x);
341 #endif
343 #if NEED_LIBM_TGAMMAF
344 float tgammaf(float x)
346 return tgamma(x);
348 #endif
350 #if NEED_LIBM_CEILF
351 float ceilf(float x)
353 return ceil(x);
355 #endif
357 #if NEED_LIBM_FLOORF
358 float floorf(float x)
360 return floor(x);
362 #endif
364 #if NEED_LIBM_NEARBYINTF
365 float nearbyintf(float x)
367 return nearbyint(x);
369 #endif
371 #if NEED_LIBM_RINTF
372 float rintf(float x)
374 return rint(x);
376 #endif
378 #if NEED_LIBM_LRINTF
379 long lrintf(float x)
381 return lrint(x);
383 #endif
385 #if NEED_LIBM_LLRINTF
386 long long llrintf(float x)
388 return llrint(x);
390 #endif
392 #if NEED_LIBM_ROUNDF
393 float roundf(float x)
395 return round(x);
397 #endif
399 #if NEED_LIBM_LROUNDF
400 long lroundf(float x)
402 return lround(x);
404 #endif
406 #if NEED_LIBM_LLRINTF
407 long long llroundf(float x)
409 return llround(x);
411 #endif
413 #if NEED_LIBM_TRUNCF
414 float truncf(float x)
416 return trunc(x);
418 #endif
420 #if NEED_LIBM_FDIMF
421 float fdimf(float x, float y)
423 return fdim(x, y);
425 #endif
427 #if NEED_LIBM_FMAXF
428 float fmaxf(float x, float y)
430 return fmax(x, y);
432 #endif
434 #if NEED_LIBM_FMINF
435 float fminf(float x, float y)
437 return fmin(x, y);
439 #endif
441 #if NEED_LIBM_FMAF
442 float fmaf(float x, float y, float z)
444 return fma(x, y, z);
446 #endif