Is this a bug or a VERY sneaky case?

Rumbu rumbu at rumbu.ro
Sat Dec 25 21:43:39 UTC 2021


On Saturday, 25 December 2021 at 20:50:12 UTC, rempas wrote:
> On Saturday, 25 December 2021 at 17:29:37 UTC, Rumbu wrote:
>>
>> And max length of a integral can be obtained using 
>> ```log10(n)+1```, you don't need a bunch of static ifs.
>
> Now you found the guy to talk about maths.... Could you mind 
> giving a demonstration?

It's common sense, log10 means "give me the power of 10 to obtain 
n". And we know that 10^x means 1 followed by x zeroes, hence the 
maximum width for the number. You add 1 because of the 1 before 
the zeroes.

So if we take as an example ubyte.max, we have ```log10(255) = 
2.4```. Truncated as int, you get ```2```. Add ```1``` and you 
obtain ```3```, the exact length of ```255```.

Or you can take 1000. ```log10(1000) = 3```, add ```1```, you 
obtain ```4```, the exact length of ```1000```.







More information about the Digitalmars-d mailing list