altfloat-0.2.2
[altfloat.git] / c99-compat.c
blobae8772923262f41b09ce63c2a24cd84f33b18fd4
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.
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 x*y + z;
43 #endif
45 #if NEED_LIBM_REMQUO
46 double remquo(double x, double y, int *quo)
48 unsigned tmp = fabs(round(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