Name

Math.pow( ) Method — raise a number to a specified power

Availability

Flash 5; may be used when exporting Flash 4 movies

Synopsis

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.

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 / (base abs(exponent)). If exponent is a fraction, pow( ) can be used to take, say, the square root or cube root 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

Build 30 of the Flash 5 Player 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.

See Also

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

Get ActionScript: The Definitive Guide now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.