On Fri, Feb 21, 2025 at 6:20 PM Thomas Munro <thomas.mu...@gmail.com> wrote: > #define PROCNUMBER_BITS 18 > #define MAX_BACKENDS ((1 << PROCNUMBER_BITS) - 1) > #define PROCNUMBER_CHARS DECIMAL_DIGITS_FOR_BITS(PROCNUMBER_BITS) > > ... with a little helper ported to preprocessor hell from Hacker's > Delight magic[1] for that last bit. See attached. But if that's a > bit too nuts...
Erm, wait of course you just need: #define DECIMAL_DIGITS(n) \ ((n) < 10 ? 1 : \ (n) < 100 ? 2 : \ (n) < 1000 ? 3 : \ (n) < 10000 ? 4 : \ (n) < 100000 ? 5 : \ (n) < 1000000 ? 6 : \ (n) < 10000000 ? 7 : \ (n) < 100000000 ? 8 : \ (n) < 1000000000 ? 9 : 10) #define PROCNUMBER_BITS 18 #define MAX_BACKENDS ((1 << PROCNUMBER_BITS) - 1) #define PROCNUMBER_CHARS DECIMAL_DIGITS(MAX_BACKENDS)