double n = -1/MathPow(5.5, 0.2); Print(n);
I need to write a function that works with powers and in the process I've discovered something interesting:
If I substitute a negative fractional number to a negative fractional power, MQL5 writes -nan.
I checked it in C++ and got the same result (I don't know what version of the language was used, because I was too lazy to compile and I've just tested it by cpp.sh).
The pluses give the same answer, there is no error in MQL5! But what is the reason for such an answer? If we use mathematics, the answer should be given. Mathematically, a number to the negative power is equal to one divided by the same number to the positive power. In other words:
And the calculator on the computer confirms it. So what is this thing with degrees?
In R:
(-5.5)^-0.2=NaN
-5.5^-0.2=-(5.5^-0.2)=-0.7110947
in R:
(-5.5)^-0.2=NaN
-5.5^-0.2=-(5.5^-0.2)=-0.7110947
Perhaps the legs are growing from the fact that you can't take an even root from a negative number ? I'm already somewhat confused... And most importantly how to get around it ?
And most importantly how to get around it ?
m = 2
n = 10
double result = pow(pow(-5.5,2.0),-0.1); Print("result = ",result); //result = 0.7110947333604484without brackets, the minus sign can be interpreted differently, imho
There will be a problem with the signs. The root of an even power is always positive
There will be a problem with the signs. The root of an even power is always positive.
In calculator where the degree is fractional
1/(-5.5 ^ -0.2) -0,7110947333604484236326007791589
In mql where the degree is fractional
double n = 1/MathPow(-5.5, -0.2); Print(n); zero divide in 'Pow.mq5'
In mql where the degree is integer.
double n = 1/MathPow(-3.0, -3.0); Print(n); -27.0
Conclusion, the function does not correctly count fractional powers, and returns zero divide.
m = 2
n = 10
without brackets the minus sign can be interpreted differently, imhoThank you for the answer, but in general if we take an arithmetically correct solution, it seems that only complex numbers can be used to implement such a solution... In your proposed method it is necessary to divide the degree so that the underlying value always has a positive degree and the answer will always be positive. But if you take without this fitting - we come only to complex numbers, because according to generally accepted algebraic model as far as I know (I'm not a mathematician by education) - the root of a negative number will be a complex number.
In mql where is the fractional degree
In mql where the degree is fractional
In mql where the degree is integer.
Conclusion, the function does not correctly count fractional degrees, and returns zero divide.
The function is correct. The standard maths just doesn't work there)
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
I need to write a function that works with powers and in the process I've discovered something interesting:
If I substitute a negative fractional number to a negative fractional power, MQL5 writes -nan.
I checked it in C++ and got the same result (I don't know what version of the language was used, because I was too lazy to compile and I've just tested it by cpp.sh).
I think there is no error in MQL5 if the answer is the same in pluses! But the question is why it happens that way? If we do the maths then the answer should be there. Mathematically, a negative number is equal to one divided by the same number to the positive power. In other words:
And the calculator on the computer confirms it. So what is this trick with grades?