diff options
Diffstat (limited to 'src/utils/math.h')
| -rw-r--r-- | src/utils/math.h | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/src/utils/math.h b/src/utils/math.h index 21fc60b..a9d9b85 100644 --- a/src/utils/math.h +++ b/src/utils/math.h | |||
| @@ -10,6 +10,7 @@ STATIC void indextoperm(int64_t, size_t n, uint8_t [n]); | |||
| 10 | STATIC int permsign(size_t n, const uint8_t [n]); | 10 | STATIC int permsign(size_t n, const uint8_t [n]); |
| 11 | STATIC int64_t digitstosumzero(size_t n, const uint8_t [n], uint8_t); | 11 | STATIC int64_t digitstosumzero(size_t n, const uint8_t [n], uint8_t); |
| 12 | STATIC void sumzerotodigits(int64_t, size_t n, uint8_t, uint8_t [n]); | 12 | STATIC void sumzerotodigits(int64_t, size_t n, uint8_t, uint8_t [n]); |
| 13 | STATIC double intpow(double, uint64_t); | ||
| 13 | 14 | ||
| 14 | STATIC int64_t | 15 | STATIC int64_t |
| 15 | factorial(int64_t n) | 16 | factorial(int64_t n) |
| @@ -183,3 +184,16 @@ sumzerotodigits(int64_t d, size_t n, uint8_t b, uint8_t a[n]) | |||
| 183 | sumzerotodigits_error: | 184 | sumzerotodigits_error: |
| 184 | memset(a, UINT8_ERROR, n); | 185 | memset(a, UINT8_ERROR, n); |
| 185 | } | 186 | } |
| 187 | |||
| 188 | STATIC double | ||
| 189 | intpow(double b, uint64_t e) | ||
| 190 | { | ||
| 191 | double r; | ||
| 192 | |||
| 193 | if (e == 0) | ||
| 194 | return 1; | ||
| 195 | |||
| 196 | r = intpow(b, e/2); | ||
| 197 | |||
| 198 | return e % 2 == 0 ? r * r : b * r * r; | ||
| 199 | } | ||
