PHP provides pow
function and **
operator. The pow
function takes two arguments: the base and the exponent, and returns the result of raising the base to the power of the exponent. On the other hand, the **
operator is a shorthand syntax for exponentiation, providing a more concise way to perform the same operation.
<?php
echo pow(2, 4); // 16
echo 2 ** 4; // 16
Since PHP 8.4, raising 0 to a negative exponent is deprecated by using the pow
function and the **
operator.
<?php
echo pow(0, -4); // INF, Deprecated: Power of base 0 and negative exponent is deprecated ...
echo 0 ** -4; // INF, Deprecated: Power of base 0 and negative exponent is deprecated ...
Starting with PHP 8.4, the fpow
function can be used for raising one number to the power of another according to the IEEE 754 standard. Unlike the pow
or the **
operator, fpow
returns INF when 0 is raised to a negative exponent and does not trigger a deprecation notice.
<?php
echo fpow(2, 4); // 16
echo fpow(0, -4); // INF
Leave a Comment
Cancel reply