MathAbs
Here are manual versions:
number=number*(-1 + (2 * (number > -1)));
number=(number < NULL) ? number * -1 : number;
Oh, here, try this, it's easier....
😂
#define inline_MathAbs(x) ((x < NULL) ? x * -1: x)
number=inline_MathAbs(number);
I would dare to claim this version is the fastest possible:
What do you think?
number=number * ((number < NULL) ? -1 : 1)
number=number<0?-number:number;
number=sqrt(pow(number,2));
For those who _really_ like to complicate things and spend resources. :)
There can be a bit negation as well
pos=~num+1
but the fastest way should be
MathAbs
if the compiler is written correctly, because the function should develop to the fastest machine code available
Thanks folks.
It’s very useful this kind of post with many suggestions.
I think the best users choice should be the fastest way.
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
Is there a diferent way or a function to return the positive value of a number?
I know I can use this kind of code, but is there any simple way?