How about:

m = 10;
d = 1;

while ( val >= m ) {
        m *= 10;
        d++;
}

... and not have a *divide* in there?

Man, entering code on a cell phone sucks...
        

Ingo Molnar <mi...@kernel.org> wrote:
>
>* Borislav Petkov <b...@alien8.de> wrote:
>
>> @@ -2,6 +2,10 @@ int num_digits(int val)
>>  {
>>      int digits = 0;
>>  
>> +    /* Handle special case */
>> +    if (!val)
>> +            return 1;
>> +
>>      while (val) {
>>              val /= 10;
>>              digits++;
>
>Hm. I suspect this could then be written as:
>
>int num_digits(int val)
>{
>       int digits = 0;
>
>       do {
>               val /= 10;
>               digits++;
>       } while (val);
>
>       return digits;
>}
>
>No ugly special case! :-)
>
>Thanks,
>
>       Ingo

-- 
Sent from my mobile phone.  Please pardon brevity and lack of formatting.
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

Reply via email to