diff options
| author | Sebastiano Tronto <sebastiano@tronto.net> | 2025-03-29 10:04:16 +0100 |
|---|---|---|
| committer | Sebastiano Tronto <sebastiano@tronto.net> | 2025-03-29 10:04:16 +0100 |
| commit | b6c1ff6cfdfe0f4ce602fe83e54c3112a1c95690 (patch) | |
| tree | f9d61c905194276dcf632e31e07ec485b172b131 /src/utils | |
| parent | 0f23987edbbabdf88fbe175f695b4fdb727586fd (diff) | |
| download | nissy-core-b6c1ff6cfdfe0f4ce602fe83e54c3112a1c95690.tar.gz nissy-core-b6c1ff6cfdfe0f4ce602fe83e54c3112a1c95690.zip | |
Optimize genptable for coordinate solve (20x speedup)
Diffstat (limited to '')
| -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 | } | ||
