From b6c1ff6cfdfe0f4ce602fe83e54c3112a1c95690 Mon Sep 17 00:00:00 2001 From: Sebastiano Tronto Date: Sat, 29 Mar 2025 10:04:16 +0100 Subject: Optimize genptable for coordinate solve (20x speedup) --- src/utils/math.h | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'src/utils/math.h') 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]); STATIC int permsign(size_t n, const uint8_t [n]); STATIC int64_t digitstosumzero(size_t n, const uint8_t [n], uint8_t); STATIC void sumzerotodigits(int64_t, size_t n, uint8_t, uint8_t [n]); +STATIC double intpow(double, uint64_t); STATIC int64_t factorial(int64_t n) @@ -183,3 +184,16 @@ sumzerotodigits(int64_t d, size_t n, uint8_t b, uint8_t a[n]) sumzerotodigits_error: memset(a, UINT8_ERROR, n); } + +STATIC double +intpow(double b, uint64_t e) +{ + double r; + + if (e == 0) + return 1; + + r = intpow(b, e/2); + + return e % 2 == 0 ? r * r : b * r * r; +} -- cgit v1.3