From: Henner Zeller Date: Mon, 1 Feb 2021 19:23:44 +0000 (-0800) Subject: Provide an integer implementation of decimal_digits(). X-Git-Tag: working-ls180~34^2 X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=5eff0b73ae82ee490be3e732241eb22cb4bff952;p=yosys.git Provide an integer implementation of decimal_digits(). Signed-off-by: Henner Zeller --- 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