From 13a3b144fe42c0299b01ce86f6d289807be35c20 Mon Sep 17 00:00:00 2001 From: Matthieu Schaller <schaller@strw.leidenuniv.nl> Date: Thu, 23 Apr 2020 14:48:20 +0200 Subject: [PATCH] Make the integer pow() code compile with GCC --- src/integer_power.h | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/src/integer_power.h b/src/integer_power.h index 3c4003dded..c8c2d86412 100644 --- a/src/integer_power.h +++ b/src/integer_power.h @@ -26,18 +26,17 @@ #include "error.h" #include "inline.h" +/* Standard headers */ +#include <math.h> + /** * @brief Computes the power of x to the n for a (small) positive integer n. * - * Only valid for values 0 <= n <= 8. + * Only optimized for values 0 <= n <= 8. Defaults to pow() above. */ __attribute__((const)) INLINE static int integer_pow(const double x, const unsigned int n) { -#ifdef SWIFT_DEBUG_CHECKS - assert(n <= 8); -#endif - switch (n) { case 0: return 1.; @@ -68,21 +67,19 @@ __attribute__((const)) INLINE static int integer_pow(const double x, const double z = y * y; return z * z; } + default: + return pow(x, (double)n); } } /** * @brief Computes the power of x to the n for a (small) positive integer n. * - * Only valid for values 0 <= n <= 8. + * Only optimized for values 0 <= n <= 8. Defaults to powf() above. */ __attribute__((const)) INLINE static int integer_powf(const float x, const unsigned int n) { -#ifdef SWIFT_DEBUG_CHECKS - assert(n <= 8); -#endif - switch (n) { case 0: return 1.f; @@ -113,6 +110,8 @@ __attribute__((const)) INLINE static int integer_powf(const float x, const float z = y * y; return z * z; } + default: + return powf(x, (float)n); } } -- GitLab