From 27869b1a379cda43900ae5146252d0501fdbb71f Mon Sep 17 00:00:00 2001 From: Alex Date: Thu, 14 Jul 2022 18:42:48 +0300 Subject: [PATCH] Don't recalculate constants at every call in isqrt. --- libs/kimath/src/geometry/seg.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/libs/kimath/src/geometry/seg.cpp b/libs/kimath/src/geometry/seg.cpp index 479317bd95..a15d62c9a5 100644 --- a/libs/kimath/src/geometry/seg.cpp +++ b/libs/kimath/src/geometry/seg.cpp @@ -54,11 +54,14 @@ constexpr T ct_sqrt(T x) return sqrt_helper(x, 0, x / 2 + 1); } +template +static constexpr T sqrt_max_typed = ct_sqrt( std::numeric_limits::max() ); + template T isqrt(T x) { T r = (T) std::sqrt((double) x); - T sqrt_max = ct_sqrt(std::numeric_limits::max()); + T sqrt_max = sqrt_max_typed; while (r < sqrt_max && r * r < x) r++;