Math.sqrt( ) Method | Flash 5; can be used when exporting Flash 4 movies |
calculate the square root of a number |
A nonnegative integer.
The square root of x, or NaN if x is less than 0.
The sqrt( ) method returns the positive root of its operand (even though there may also be a mathematically valid negative root). It is equivalent to:
Math.pow(x, 0.5)
Math.sqrt(4); // Returns 2, although -2 is also a valid root Math.sqrt(36); // Returns 6, although -6 is also a valid root Math.sqrt(-20); // Returns NaN // Calculate the distance between two points, // the square root of (deltaX squared plus deltaY squared): var dist = Math.sqrt((deltaX * deltaX) + (deltaY * deltaY));
Math.pow( ), Math.SQRT2, Math.SQRT1_2