# HG changeset patch # User Rubidium # Date 2024-02-08 19:32:36 # Node ID ec7139d22b7dbe1dc6ca8f9911f89ad59102a768 # Parent d49703f1fa46336fa14fc51944fccb083d2710e4 Codechange: Add function to get the power of ten for a given number diff --git a/src/core/math_func.hpp b/src/core/math_func.hpp --- a/src/core/math_func.hpp +++ b/src/core/math_func.hpp @@ -350,6 +350,19 @@ constexpr int RoundDivSU(int a, uint b) } } +/** + * Computes ten to the given power. + * @param power The power of ten to get. + * @return The power of ten. + */ +constexpr uint64_t PowerOfTen(int power) +{ + assert(power >= 0 && power <= 20 /* digits in uint64_t */); + uint64_t result = 1; + for (int i = 0; i < power; i++) result *= 10; + return result; +} + uint32_t IntSqrt(uint32_t num); #endif /* MATH_FUNC_HPP */