Feature request of sign(x) function.

 
I don't see the sign of a variable as a function in the docs. I would like to request this feature/function. This can already be achieved using if statements and sped up using branchless techniques but it would be nice to have a super fast simple function that returns 1 for positive, 0 for 0, and -1 for negative.
 
double MathSign(const double value)
  {
   return (value > 0) - (value < 0);
  }

https://www.mql5.com/en/code/20822

Math Utils
Math Utils
  • www.mql5.com
Handy functions for comparison, rounding, formatting and debugging of doubles (prices, lots and money).
 
I would make it a template so it works with any (comparable) datatype.
template <typename T>
T MathSign(T value){ return (value > 0) - (value < 0); }
 
William Roeder #:
I would make it a template so it works with any (comparable) datatype.

I think it is now is the right time for MetaQuotes to start revising source code of their math functions to fix reported errors and add some new functionality.