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:

Example code:

   <HTML>

   <HEAD>

   </HEAD>

   <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>

See also:Math object, Math.sqrt(), Power function, Zero value

Cross-references:

ECMA 262 edition 2 - section - 15.8.2.13

ECMA 262 edition 3 - section - 15.8.2.13