From f0c50ad5298ae7721431049534d99fbc45990314 Mon Sep 17 00:00:00 2001 From: Rubidium Date: Thu, 8 Feb 2024 20:32:36 +0100 Subject: [PATCH] Codechange: Add function to get the power of ten for a given number --- src/core/math_func.hpp | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/core/math_func.hpp b/src/core/math_func.hpp index 1417c0f793..f5cc83d82c 100644 --- 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 */