diff options
-rw-r--r-- | numpy/core/src/umath_funcs_c99.inc.src | 74 |
1 files changed, 26 insertions, 48 deletions
diff --git a/numpy/core/src/umath_funcs_c99.inc.src b/numpy/core/src/umath_funcs_c99.inc.src index 7122eb10b..fc621d047 100644 --- a/numpy/core/src/umath_funcs_c99.inc.src +++ b/numpy/core/src/umath_funcs_c99.inc.src @@ -17,9 +17,7 @@ * can be linked from the math library. The result can depend on the * optimization flags as well as the compiler, so can't be known ahead of * time. If the function can't be linked, then either it is absent, defined - * as a macro, or is an intrinsic (hardware) function. If it is linkable it - * may still be the case that no prototype is available. So to cover all the - * cases requires the following construction. + * as a macro, or is an intrinsic (hardware) function. * * i) Undefine any possible macros: * @@ -27,27 +25,20 @@ * #undef foo * #endif * - * ii) Check if the function was in the library, If not, define the - * function with npy_ prepended to its name to avoid conflict with any - * intrinsic versions, then use a define so that the preprocessor will - * replace foo with npy_foo before the compilation pass. Make the - * function static to avoid poluting the module library. + * ii) Avoid as much as possible to declare any function here. Declaring + * functions is not portable: some platforms define some function inline + * with a non standard identifier, for example, or may put another + * idendifier which changes the calling convention of the function. If you + * really have to, ALWAYS declare it for the one platform you are dealing + * with: * - * #ifdef foo - * #undef foo - * #endif - * #ifndef HAVE_FOO - * static double - * npy_foo(double x) - * { - * return x; - * } - * #define foo npy_foo + * Not ok: + * double exp(double a); * - * iii) Avoid as much as possible to declare any function here. Declaring - * functions is not portable: some platforms define some function inline - * with a non standard identifier, for example. If you really have to, - * ALWAYS declare it for the one platform you are dealing with + * Ok: + * #ifdef SYMBOL_DEFINED_WEIRD_PLATFORM + * double exp(double); + * #endif */ /* @@ -66,7 +57,7 @@ /* Original code by Konrad Hinsen. */ #ifndef HAVE_EXPM1 static double -npy_expm1(double x) +expm1(double x) { double u = exp(x); if (u == 1.0) { @@ -77,12 +68,11 @@ npy_expm1(double x) return (u-1.0) * x/log(u); } } -#define expm1 npy_expm1 #endif #ifndef HAVE_LOG1P static double -npy_log1p(double x) +log1p(double x) { double u = 1. + x; if (u == 1.0) { @@ -91,12 +81,11 @@ npy_log1p(double x) return log(u) * x / (u - 1); } } -#define log1p npy_log1p #endif #ifndef HAVE_HYPOT static double -npy_hypot(double x, double y) +hypot(double x, double y) { double yx; @@ -114,21 +103,19 @@ npy_hypot(double x, double y) return x*sqrt(1.+yx*yx); } } -#define hypot npy_hypot #endif #ifndef HAVE_ACOSH static double -npy_acosh(double x) +acosh(double x) { return 2*log(sqrt((x+1.0)/2)+sqrt((x-1.0)/2)); } -#define acosh npy_acosh #endif #ifndef HAVE_ASINH static double -npy_asinh(double xx) +asinh(double xx) { double x, d; int sign; @@ -147,12 +134,11 @@ npy_asinh(double xx) } return sign*log1p(x*(1.0 + x/(d+1))); } -#define asinh npy_asinh #endif #ifndef HAVE_ATANH static double -npy_atanh(double x) +atanh(double x) { if (x > 0) { return -0.5*log1p(-2.0*x/(1.0 + x)); @@ -161,12 +147,11 @@ npy_atanh(double x) return 0.5*log1p(2.0*x/(1.0 - x)); } } -#define atanh npy_atanh #endif #ifndef HAVE_RINT static double -npy_rint(double x) +rint(double x) { double y, r; @@ -185,37 +170,33 @@ npy_rint(double x) } return y; } -#define rint npy_rint #endif #ifndef HAVE_TRUNC static double -npy_trunc(double x) +trunc(double x) { return x < 0 ? ceil(x) : floor(x); } -#define trunc npy_trunc #endif #ifndef HAVE_EXP2 #define LOG2 0.69314718055994530943 static double -npy_exp2(double x) +exp2(double x) { return exp(LOG2*x); } -#define exp2 npy_exp2 #undef LOG2 #endif #ifndef HAVE_LOG2 #define INVLOG2 1.4426950408889634074 static double -npy_log2(double x) +log2(double x) { return INVLOG2*log(x); } -#define log2 npy_log2 #undef INVLOG2 #endif @@ -295,11 +276,10 @@ static int signbit_ld (long double x) #endif #ifndef HAVE_@KIND@@C@ static @type@ -npy_@kind@@c@(@type@ x) +@kind@@c@(@type@ x) { return (@type@) @kind@((double)x); } -#define @kind@@c@ npy_@kind@@c@ #endif /**end repeat1**/ @@ -313,11 +293,10 @@ npy_@kind@@c@(@type@ x) #endif #ifndef HAVE_@KIND@@C@ static @type@ -npy_@kind@@c@(@type@ x, @type@ y) +@kind@@c@(@type@ x, @type@ y) { return (@type@) @kind@((double)x, (double) y); } -#define @kind@@c@ npy_@kind@@c@ #endif /**end repeat1**/ @@ -326,14 +305,13 @@ npy_@kind@@c@(@type@ x, @type@ y) #endif #ifndef HAVE_MODF@C@ static @type@ -npy_modf@c@(@type@ x, @type@ *iptr) +modf@c@(@type@ x, @type@ *iptr) { double niptr; double y = modf((double)x, &niptr); *iptr = (@type@) niptr; return (@type@) y; } -#define modf@c@ npy_modf@c@ #endif /**end repeat**/ |