From dd39c90f134eff8e5d01ca740ba5464a70341177 Mon Sep 17 00:00:00 2001 From: Stefan Harmuth Date: Sat, 7 Dec 2024 06:35:55 +0100 Subject: [PATCH] math.magnitude(): return order of magnitude of a number --- src/tools/math.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/tools/math.py b/src/tools/math.py index 6a58baf..43553b2 100644 --- a/src/tools/math.py +++ b/src/tools/math.py @@ -26,3 +26,7 @@ def mul(ints: Iterable[int]) -> int: ret *= x return ret + + +def magnitude(value: int | float) -> int: + return math.floor(math.log10(value))