Changeset - r28766:ec7139d22b7d
[Not reviewed]
master
0 1 0
Rubidium - 10 months ago 2024-02-08 19:32:36
rubidium@openttd.org
Codechange: Add function to get the power of ten for a given number
1 file changed with 13 insertions and 0 deletions:
0 comments (0 inline, 0 general)
src/core/math_func.hpp
Show inline comments
 
@@ -347,9 +347,22 @@ constexpr int RoundDivSU(int a, uint b)
 
	} else {
 
		/* -0.5 is rounded to 0 */
 
		return (a - (static_cast<int>(b) - 1) / 2) / static_cast<int>(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 */
0 comments (0 inline, 0 general)