
Math.sqrt() Method
This is the Title of the Book, eMatter Edition
Copyright © 2007 O’Reilly & Associates, Inc. All rights reserved.
614
|
ActionScript Language Reference
Math.sqrt() Method
calculate the square root of a number
Flash 5; can be used when exporting Flash 4 movies
Math.sqrt(x)
Arguments
x A nonnegative integer.
Returns
The square root of x, or NaN if x is less than 0.
Description
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)
Example
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));
See Also
Math.pow( ), Math.SQRT2, Math.SQRT1_2
Math.SQRT1_2 Property
the reciprocal of the square root of 2, approximately 0.70711
Flash 5; can be used when exporting Flash 4 movies
Math.SQRT1_2
Description
The SQRT1_2 property is a constant approximating the value 1/Math.SQRT2 (the reciprocal of
the square root of 2), equaling approximately 0.70711.
See Also
Math.SQRT2
Math.SQRT2 Property
the square root of 2, approximately 1.41421
Flash 5; can be used when exporting Flash 4 movies
Math.SQRT2
Description
The SQRT2 property is a constant approximating ...