Why are there such tricks with degrees? - page 2

 
Roman:

-0.2 is not zero to return a division by zero error.

The function returns -nan, i.e. Not a Number. and the error is thrown when trying to divide by -nan. If anything, the error text is just not appropriate.

 

Correct solution: solution is in the complex domain.


But if we are talking about having different branches of solutions for positive and negative input parameters, we just need to define these branches first:

.

Make such a feature and you'll be fine. ;)
 
Andrey Azatskiy:

The function returns -nan, i.e. Not a Number. and an error is thrown when trying to divide by -nan. If anything, the error text is just not appropriate.

Why on earth would -0.2 be -nan ?)

Another test function

In calculator.

1/(-3 ^ 3)

-27

In mql functions

double n = 1.0/MathPow(-3.0, 3.0);
Print(n);

-0.03703703703703703
 
Roman:

So why the hell is -0.2 a nan?)

Another test function

In a calculator

In an mql function.

is not -0.2 - nan, but the result of a degree increase.
The fractional degree of a number (a^m/n) is the root of degree n of a^m.
If the sub-root value is negative, it can be either negative or positive, based on the power of m and the number a itself (which in my problem is always negative, so it is positive for positive power of m and negative for negative). So if the sub-root value is negative, then the number is also negative. The root of a negative number lies in the complex area, so we can't operate on values of the complex area viathe usualdouble type, which is why the standard implementation of degree gives -nan.

Документация по MQL5: Основы языка / Типы данных / Вещественные типы (double, float)
Документация по MQL5: Основы языка / Типы данных / Вещественные типы (double, float)
  • www.mql5.com
Вещественные типы (или типы с плавающей точкой) представляют значения, имеющие дробную часть. В языке MQL5 есть два типа для чисел с плавающей точкой. Способ представления вещественных чисел в машинной памяти определен стандартом IEEE 754 и не зависит от платформ, операционных систем и языков программирования. Константы с плавающей точкой...
 
Олег avtomat:

Correct solution: the solution is in the complex domain.


But if we are talking about having different branches of solutions for positive and negative input parameters, then we just need to define these branches first:

.

Make such a feature and you'll be fine. ;)

Thank you for your detailed answer. But for me complex calculus is not suitable for my problem, so most likely I will limit myself to natural numbers and as a result I will not fall into the complex domain.

 
Andrey Azatskiy:

Thank you for your detailed reply. But for me the complex calculus is not suitable for my problem, so I will most likely limit myself to natural numbers and as a result will not fall into the complex area.

That's what I'm talking about, and I specifically showed you an example. Look at it carefully. This example is exactly for your case.

zy

translating to µl is very easy

 
Andrey Azatskiy:

is not -0.2 - nan, but the result of a degree.
The power of a fractional number (a^m/n) is the root of degree n of a^m.
If the sub-root value is negative, it can be either negative or positive based on the power of m and the number a itself (which in my problem is always negative, so it is positive at positive power of m and negative at negative). So if the sub-root value is negative, then the number is also negative. The root of a negative number lies in the complex area, so we can't operate on values of the complex area via the usual double type, which is why the standard implementation of the degree gives -nan.

Andrey, yes, I misspoke, it is clear that the result of raising to a power returns -nan.
But this result gives rise to a fractional powers, where the integer is zero -0.2
The calculator calculates everything correctly.

And the previous test, too, does not count as in the calculator.

 
Олег avtomat:

That's what I'm talking about, and I specifically gave you an example. Take a good look.

Yes, I got it. Thank you. (even the formula is written down)

 
Andrey Azatskiy:

Perhaps the legs grow from the fact that you can't take an even root from a negative number ? I'm already a bit confused... And most importantly how to get around it ?

Whole degrees are determined simply by multiplication (and taking the inverse for negative exponents), so are easily transferred to negative bases. Fractional degrees are defined via logarithm and exponent: y^x=exp(x*ln(y)) and with negative numbers come to the complex plane. The logarithm has an infinite number of branches and to avoid the hassle of finding the right branch, they return NAN.

 
Andrey Azatskiy:

Thank you for your 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 split 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, in fact according to generally accepted algebraic model as I know (I'm not a mathematician by education) - the root of a negative number will be a complex number.

use the formula I suggested above.

Here's the same formula:

void OnStart()
  {
   int m = 2;
   int n = 10;
   
   double result = 1.0/pow(pow(-5.5,m),1.0/n); 		// result = 0.7110947333604484
   Print("result = ",result);
  }

and here is an example of how to convert a double into a fraction

https://www.mql5.com/ru/forum/290279#comment_9396706

Число в дробь (convert double to fraction)
Число в дробь (convert double to fraction)
  • 2018.11.16
  • www.mql5.com
Ищу способ преобразовать вещественное число в дробь, нагуглил исходник https://stackoverflow...