Pythagorean Theorem

 

hi

i want to know how to code for Pythagorean Theorem in mql4

if my equation is =sqrt((a^2)+(b^2))

and a=b

can we do that by using :

double MathPow( double base, double exponent) 


any help is appreciated

 

For the second power, a*a is a bit shorter than MathPow(a,2), but that's a matter of taste.

double c;
c=MathSqrt(a*a+b*b);

If a=b is given then

double c;
c=MathSqrt(2.0)*a;

(I'm not really sure that type casting applies to MathSqrt(), but better be safe than sorry. :)

 
Drave:

For the second power, a*a is a bit shorter than MathPow(a,2), but that's a matter of taste.

If a=b is given then

(I'm not really sure that type casting applies to MathSqrt(), but better be safe than sorry. :)



hi

thanks for ur help Drave....i will tray this

 
Drave:

For the second power, a*a is a bit shorter than MathPow(a,2), but that's a matter of taste.

If a=b is given then

(I'm not really sure that type casting applies to MathSqrt(), but better be safe than sorry. :)


I don't like leaving type-casting in doubt either, just heads-up to save yourself from typing a lot of needless zeroes, all you need to do in order establish that a given value be typecast as a double instead of an integer is to append the decimal marker to it, the zero after the decimal point is not necessary.
double c;
c=MathSqrt(2.)*a;   // 2. is typecast as a double, the same as typing 2.0 or 2.00 or 2.000
 
1005phillip:

I don't like leaving type-casting in doubt either, just heads-up to save yourself from typing a lot of needless zeroes, all you need to do in order establish that a given value be typecast as a double instead of an integer is to append the decimal marker to it, the zero after the decimal point is not necessary.


hi

sorry for late reply.....but want to thank 1005phillip for his hint..... i appreciate

 
The type-cast isn't necessary as the 2 will be doubled before passing to sqrt. I do it 1) for clarity and 2) I'm not sure the compiler is smart enough to double it during compilation as opposed to run time.
Reason: