From 5eff0b73ae82ee490be3e732241eb22cb4bff952 Mon Sep 17 00:00:00 2001 From: Henner Zeller Date: Mon, 1 Feb 2021 11:23:44 -0800 Subject: [PATCH] Provide an integer implementation of decimal_digits(). Signed-off-by: Henner Zeller --- frontends/aiger/aigerparse.cc | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/frontends/aiger/aigerparse.cc b/frontends/aiger/aigerparse.cc index 2d7c2187e..463c5965b 100644 --- a/frontends/aiger/aigerparse.cc +++ b/frontends/aiger/aigerparse.cc @@ -55,8 +55,15 @@ inline int32_t from_big_endian(int32_t i32) { #define log_debug2(...) ; //#define log_debug2(...) log_debug(__VA_ARGS__) -static int decimal_digits(unsigned n) { - return n > 1 ? ceil(log10(n)) : 1; +static int decimal_digits(uint32_t n) { + static uint32_t digit_cutoff[9] = { + 10, 100, 1000, 10000, 100000, + 1000000, 10000000, 100000000, 1000000000 + }; + for (int i = 0; i < 9; ++i) { + if (n < digit_cutoff[i]) return i + 1; + } + return 10; } struct ConstEvalAig -- 2.30.2