zlacker

[parent] [thread] 3 comments
1. Mauran+(OP)[view] [source] 2019-11-11 15:56:05
It's a single multiplication - with an irrational (transcendental, actually) number. That is most certainly not "easy" for a computer, and elsewhere in the comments you can see how much of a problem that actually poses.

Also, counting digits in base 2 is not the log2. The former gives you the latter but not the reverse. Finding the number of decimal digits in a number given in base 2 is not a simplification.

replies(1): >>gpdere+q8
2. gpdere+q8[view] [source] 2019-11-11 16:50:41
>>Mauran+(OP)
Oh, agree that for arbitrary large or non integer inputs it might not work. But elsethread jepler has shown a solution off Hacker's Delight which which simply multiplies the index of the most significant bit with a magic constant.
replies(2): >>Mauran+bA >>slavik+bC
◧◩
3. Mauran+bA[view] [source] [discussion] 2019-11-11 19:32:33
>>gpdere+q8
> But elsethread jepler has shown a solution off Hacker's Delight which which simply multiplies the index of the most significant bit with a magic constant.

...and then checks for and corrects the potential off-by-one thus incurred.

◧◩
4. slavik+bC[view] [source] [discussion] 2019-11-11 19:46:47
>>gpdere+q8
When N is fixed, all algorithms become O(1). That's why they appear the same.

If you do these calculations by hand, the complexity will be more obvious because each operation will be smaller.

[go to top]