If we proceed from the task " how to make equal faster"... Then we should reduce possible conventions and operations. In my opinion switch will be the fastest at the level of assembly registers.
And the remainder from division is an expensive operation. That's what Renat wrote.
Allow the use of cookies to log in to the MQL5.com website.
Please enable the necessary setting in your browser, otherwise you will not be able to log in.
You are signed in. Two-factor authentication has been disabled. Set it up again and scan a new QR code, or continue with two-factor authentication disabled.
There is a variable X that can take the values 0, 1 and other values.
When X is 0 or 1, how to quickly and elegantly make it equal to 1 or 0 respectively?
That's the only way I know:
There is a variable X that can take the values 0, 1 and other values.
When X is 0 or 1, how to quickly and elegantly make it equal to 1 or 0 respectively?
That's the only way I know:
X = 1 - X;didn't realise it myself))
When X is equal to 0 or 1, how to quickly and elegantly make it equal to 1 or 0 respectively?
Thank you)))
Thank you)))
Another option
switch(X) { case 0: X=1; break; case 1: X=0; break; default: break; }Another option
another
another
If we proceed from the task " how to make equal faster"...
Then we should reduce possible conventions and operations.
In my opinion switch will be the fastest at the level of assembly registers.
And the remainder from division is an expensive operation.
That's what Renat wrote.
another