Table of Contents

Math.pow( ) Method Flash 5; can be used when exporting Flash 4 movies

raise a number to a specified power
Math.pow(base, exponent)

Arguments

base

A number representing the base of the exponential expression.

exponent

A number representing the power (i.e., exponent) to which to raise base. If the base is negative, the exponent must be an integer, else NaN is returned.

Returns

The base raised to the power exponent.

Description

The pow( ) method can be used to raise any number to any power. If exponent is negative, pow( ) returns 1 / (baseabs(exponent)). If exponent is a fraction, pow( ) can be used to take the square root or cube root, and so on, of a number (in which case it returns the positive root, although, mathematically, there may also be a negative root).

Example

Math.pow(5, 2);    // Returns 25 (5 squared)
Math.pow(5, 3);    // Returns 125 (5 cubed)
Math.pow(5, -2);   // Returns 0.04 (1 divided by 25)
Math.pow(8, 1/3);  // Returns 2 (cube root of 8)
Math.pow(9, 1/2);  // Returns 3 (square root of 9)
Math.pow(10, 6);   // Returns 1000000 (can also be written as 1e6)

Bugs

Flash Player 5.0.30.0 did not correctly calculate Math.pow( ) for negative values of base. For example, Math.pow(-2, 2) was calculated as NaN, whereas it should be 4. This was fixed in Flash Player 6.

See Also

Math.exp( ), Math.sqrt( ), Math.SQRT2, Math.SQRT1_2


Table of Contents