Name
pow()
Synopsis
number pow ( numberbase, numberexponent)
The pow()
function takes two parameters: a base and a power to raise it by. That is, supplying 2 as parameter two will multiply parameter one by itself, and supplying 3 will multiply parameter one by itself twice, like this:
print pow(10,2); // 100
print pow(10,3); // 1000
print pow(10,4); // 10000
print pow(-10, 4); // 10000The first three lines show the result of 10 * 10, 10 * 10 * 10, then 10 * 10 * 10 * 10. On line four, we have -10 as the first parameter, and it is converted to a positive number in the result. This is basic mathematical theory: "a negative multiplied by negative makes a positive."
You can also send negative powers for the second parameter to pow() to generate roots. For example, pow(10, -1) is 0.1, pow(10, -2) is 0.01, pow(10, -3) is 0.001, etc. The values used as parameters one and two need not be integers: pow(10.1,2.3) works fine.