# Math.pow() (Function)

The result of raising a value to the power of another value.

Availability:

 ECMAScript edition - 2 JavaScript - 1.0 JScript - 1.0 Internet Explorer - 3.02 Netscape - 2.0 Netscape Enterprise Server version - 2.0 Opera - 3.0
Property/method value type:Number primitive
JavaScript syntax:-Math.pow(aValue1, aValue2)
Argument list:aValue1Some meaningful numeric value
aValue2Some meaningful numeric value

This function returns the result of raising the first argument to the power of the second.

Special boundary conditions that affect the results are:

Argument1Argument2Result
+0< 0+infinity
+infinity< 00
+infinity> 0+infinity
-0< 0 and is an even integer+infinity
-0< 0 and is an odd integer-infinity
-infinity< 00
-infinity> 0 and is an even integer+infinty
-infinity> 0 and is an odd integer-infinty
0> 00
1Any value1
< 0 and finitefinite but non integerNaN
abs(arg) < 1+infinity0
abs(arg) < 1-infinity+infinity
abs(arg) == 1+infinityNaN
abs(arg) == 1-infinityNaN
abs(arg) > 1+infinity+infinity
abs(arg) > 1-infinity0
Any value01
Any valueNaNNaN
NaNnon zeroNaN

The exact value yielded by this function may vary slightly from implementation to implementation due to differences in the underlying precision of the implementations, math routines, and the specific algorithm selected to evaluate this function.

The example shows a simple binary number converter which exhibits some instability in the most significant bit on some platforms.

## Warnings:

• There are many boundary conditions that make this function hard to understand and therefore hard to diagnose if it goes wrong. Check both of the input arguments in case of doubt. They may have evaluated out to a strange boundary condition that yields unexpected results.

• Using MSIE on the Macintosh exhibits a instability when you raise 2 to the power 31 and test the resulting value in a bitwise expression. Netscape works correctly in this circumstance. This is demonstrated in the example.

## Example code:

<HTML>
<BODY>
<SCRIPT>
document.write(-2 + " - " + binary32(-2) + "<BR>");
document.write(-1 + " - " + binary32(-1) + "<BR>");
document.write(0 + " - " + binary32(0) + "<BR>");
document.write(1 + " - " + binary32(1) + "<BR>");
document.write(2 + " - " + binary32(2) + "<BR>");
document.write(3 + " - " + binary32(3) + "<BR>");
function binary32(aValue)
{
myArray = new Array(32);

for(myEnum=0; myEnum<32; myEnum++)
{
if(aValue & Math.pow(2, myEnum))
{
myArray[31-myEnum] = "1";
}
else
{
myArray[31-myEnum] = "0";
}
}
return myArray.join("");
}
</SCRIPT>
</BODY>
</HTML>