Features of the mql5 language, subtleties and tricks - page 116
You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register
(tired) if that were the problem, the error "'k' - redefinition; different type modifiers" would pop up, but it's not on the screenshot. So the compiler doesn't care and it's not the issue.
Well, well...
Well, well...
Well, try compiling it yourself. If you're not too lazy to write posts on this topic on the forum, you should be too lazy to put it into an editor and press F7. It's much faster.
Fast way to calculate the binary logarithm of an integer. Works 3-5 times faster than MathLog.
Fast way to calculate binary logarithm of an integer. Works 3-5 times faster than MathLog.
I use a function like this (pure shamanism, but it works):
Both functions give the correct same answer, I found no errors.
It's interesting to compare the speed of operation. My version has slightly less shift and addition operations, but there's multiplication at the end. Alexey's version has slightly more shift and addition operations, but no multiplication. How is it faster ?
My version has slightly fewer shift and addition operations, but not multiplication. Alexey's version has slightly more shift and addition operations, but no multiplication. How is it faster?
I have a maximum of 6 shift and addition operations (binary search).Shift (ulong)1<<k doesn't count, because it's a constant. The only thing is that we also check the condition. But there are always 6 operations, plus multiplication, plus one more shift and access to the managed array (i.e. index check). So your version will obviously be slower by speed :).
And your version of course looks mysterious.)
p.s. I've got an assumption, that if my code could be unwrapped into a chain of comparisons via if-else, getting rid of all the arithmetic operations, it would speed things up tremendously. But it'd be a big mess of code. If only one could use recursion in macros...
It is interesting to compare the speed.
The log2 variant is faster.
So the log2 option is faster.
Got it.
Replacing my function.