3 ms·
It's a single multiplication - with an irrational (transcendental, actually) number. That is most certainly not "easy" for a computer, and elsewhere in the comm
by MauranKilom 7y ago
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.
- gpderetta 7y agoOh, 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.
- MauranKilom 7y ago> 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.
- slavik81 7y agoWhen 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.