Features of the mql5 language, subtleties and tricks - page 313
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
Calculator for approximate integer division by a constant.
I just looked-up this and it is already called "shift and add".
For certain multipliers like multiply by 10, the result is exact.
https://www.wikiwand.com/en/articles/Multiplication_algorithm#Usage_in_computers
In base two, long multiplication is sometimes called "shift and add", because the algorithm simplifies and just consists of shifting left (multiplying by powers of two) and adding.
I just looked-up this and it is already called "shift and add".
For certain multipliers like multiply by 10, the result is exact.
https://www.wikiwand.com/en/articles/Multiplication_algorithm#Usage_in_computers
In base two, long multiplication is sometimes called "shift and add", because the algorithm simplifies and just consists of shifting left (multiplying by powers of two) and adding.
https://www.mql5.com/en/forum/393227/page280#comment_55325243
There is also a library optimizing integer division with compile-time constants, see https://libdivide.com/
it basically converts the divisor to approximate multiplier:fast_d = libdivide_s32_gen(divisor);
A minimal implementation of the fastdiv algorithm (described here https://www.wikiwand.com/en/articles/Division_algorithm?ai=topQs#Division_by_a_constant)
This demonstrates how a compiler can optimize divsion by a compile-time constant (to multiplication and shift).
NB: this fastdiv optimization cannot be applied for divisors that are unkown at compile-time (e.g., division by a runtime variable).Is there any way to choose which loop to use depending on the value of the bool variable? Inside the loops everything is the same, so I want to select the loop itself 1 time.
There is a bool variable Up. If its value is true, we need the LOOP_Up loop, if false LOOP_Down.
This option causes an error:
It doesn't work this way either:
if(Up) LOOP_Up if(!Up) LOOP_Down {