Path: csiph.com!eternal-september.org!feeder.eternal-september.org!nntp.eternal-september.org!.POSTED!not-for-mail
From: Tim Rentsch
Newsgroups: comp.lang.c
Subject: Re: Sort of trivial code challenge - may be interesting to you anyway
Date: Fri, 06 Mar 2026 08:37:35 -0800
Organization: A noiseless patient Spider
Lines: 40
Message-ID: <86eclwc3sg.fsf@linuxsc.com>
References: <10n80sc$3soe4$1@dont-email.me> <10o6vat$258sq$1@raubtier-asyl.eternal-september.org> <10o7438$2737q$2@dont-email.me> <10o92e1$2r6rf$1@raubtier-asyl.eternal-september.org> <10obb37$3jler$1@dont-email.me> <86cy1ic5fm.fsf@linuxsc.com> <86ms0lbo01.fsf@linuxsc.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Injection-Date: Fri, 06 Mar 2026 16:37:44 +0000 (UTC)
Injection-Info: dont-email.me; posting-host="b0f5cdf16a02d5dcd9e415cfd7cb6e85"; logging-data="864636"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/kUK0xh+fZk1IE1d/BC4CSIyZlMkyUPTk="
User-Agent: Gnus/5.11 (Gnus v5.11) Emacs/22.4 (gnu/linux)
Cancel-Lock: sha1:qZOfSZor8LvOJLGQV6WO6l8ZF+g= sha1:FfE39ugk1mKsaji8l5U5m2FokEc=
Xref: csiph.com comp.lang.c:396825
scott@slp53.sl.home (Scott Lurndal) writes:
> Tim Rentsch writes:
>
>> scott@slp53.sl.home (Scott Lurndal) writes:
>>
>>> Tim Rentsch writes:
>>>
>>>> scott@slp53.sl.home (Scott Lurndal) writes:
>>>>
>>>>> DFS writes:
>>>>>
>>>>>> On 3/4/2026 5:44 AM, Bonita Montero wrote:
>>>>>>
>>>>>> int colwidth = sprintf(cw,"%d",max) + 1;
>>>>>
>>>>> using ciel(log10(rows*columns)) performs better than snprintf
>>>>> in this application.
>>>>>
>>>>>
>>>>> $ printf '%f\n' $(( ceil(log10( 8*8)) ))
>>>>> 2.000000
>>>>
>>>> Using snprintf() is more correct and also more obviously correct.
>>>
>>> Yes, I had assumed the first row, first column would be zero, not one.
>>
>> The value for 10 is also wrong. And 100. And 1000. etc...
>
> No, 10*10 yields 100 values from 0 to 99.
You changed the subject. We were talking about how to
calculate an appropriate field width given a maximum value.
The problem under discussion produces values from 1 to
maximum value, inclusive. The expression ceil(log10( max ) )
gives wrong answers when max is a power of 10. I haven't
looked at Bonita Montero's code but based on the snippet
above it seems clear he is responding to the original problem
statement, even if he may have misunderstood what that was
asking for.