Path: csiph.com!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: Tim Rentsch
Newsgroups: comp.lang.c
Subject: Re: on an analogy for verifying whether another digit fits (into an unsigned type)
Date: Fri, 21 Jan 2022 17:12:14 -0800
Organization: A noiseless patient Spider
Lines: 49
Message-ID: <86ilucpo9d.fsf@linuxsc.com>
References: <86mtjws9cg.fsf@levado.to> <86fsphrcsu.fsf@linuxsc.com> <86r191p4rk.fsf@linuxsc.com>
Mime-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Injection-Info: reader02.eternal-september.org; posting-host="434625eb2bdf5b21805d62a567edd212"; logging-data="31933"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/1teJQ4mpr6Xlkpo5L5fPjQ72mnUzY8qc="
User-Agent: Gnus/5.11 (Gnus v5.11) Emacs/22.4 (gnu/linux)
Cancel-Lock: sha1:FnDgwyImJp2Z3S2jRcoN6V3DnQE= sha1:KATBGpDMINDEvyUmeTDhVrdWbeY=
Xref: csiph.com comp.lang.c:164529
Bonita Montero writes:
> Am 21.01.2022 um 15:01 schrieb Tim Rentsch:
>
>> Bonita Montero writes:
>>
>>> Am 21.01.2022 um 04:24 schrieb Tim Rentsch:
>>>
>>>> Meredith Montgomery writes:
>>>>
>>>>> I've been trying to think of an analogy for the verification
>>>>>
>>>>> if( ((UINT64_MAX - c) / 10) >= r)
>>>>> r = r * 10 + c;
>>>>> else return -1; /* doesn't fit */
>>>>>
>>>>> in the procedure below. [...]
>>>>
>>>> No analogy needed. The condition that needs to be
>>>> satisfied is
>>>>
>>>> r * 10 + c <= UINT64_MAX
>>>>
>>>> which is the same as
>>>>
>>>> r * 10 <= UINT64_MAX - c
>>>>
>>>> which is the same as
>>>>
>>>> r <= (UINT64_MAX - c) / 10
>>>>
>>>> which is the same as
>>>>
>>>> (UINT64_MAX - c) / 10 >= r
>>>>
>>>> giving the expression in the if() test. Done.
>>>
>>> Doesn't help because c isn't a constant.
>>
>> It's hard to know what to say to such an obviously
>> inapplicable comment.
>
> If your exchanges would result in a constant instead of a
> calucaltion they would be favourable. But the overhead for
> your swapped calculation is exactly the same and the code isn't
> more readable than before.
Apparently you don't understand that your comment has no bearing
on what I was talking about.