Skip to content
Snippets Groups Projects
Commit 13a3b144 authored by Matthieu Schaller's avatar Matthieu Schaller
Browse files

Make the integer pow() code compile with GCC

parent c355ef62
No related branches found
No related tags found
1 merge request!1077Improved multipole acceptance criterion (MAC)
...@@ -26,18 +26,17 @@ ...@@ -26,18 +26,17 @@
#include "error.h" #include "error.h"
#include "inline.h" #include "inline.h"
/* Standard headers */
#include <math.h>
/** /**
* @brief Computes the power of x to the n for a (small) positive integer 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 pow() above.
*/ */
__attribute__((const)) INLINE static int integer_pow(const double x, __attribute__((const)) INLINE static int integer_pow(const double x,
const unsigned int n) { const unsigned int n) {
#ifdef SWIFT_DEBUG_CHECKS
assert(n <= 8);
#endif
switch (n) { switch (n) {
case 0: case 0:
return 1.; return 1.;
...@@ -68,21 +67,19 @@ __attribute__((const)) INLINE static int integer_pow(const double x, ...@@ -68,21 +67,19 @@ __attribute__((const)) INLINE static int integer_pow(const double x,
const double z = y * y; const double z = y * y;
return z * z; return z * z;
} }
default:
return pow(x, (double)n);
} }
} }
/** /**
* @brief Computes the power of x to the n for a (small) positive integer 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, __attribute__((const)) INLINE static int integer_powf(const float x,
const unsigned int n) { const unsigned int n) {
#ifdef SWIFT_DEBUG_CHECKS
assert(n <= 8);
#endif
switch (n) { switch (n) {
case 0: case 0:
return 1.f; return 1.f;
...@@ -113,6 +110,8 @@ __attribute__((const)) INLINE static int integer_powf(const float x, ...@@ -113,6 +110,8 @@ __attribute__((const)) INLINE static int integer_powf(const float x,
const float z = y * y; const float z = y * y;
return z * z; return z * z;
} }
default:
return powf(x, (float)n);
} }
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment