pow
Description
Syntax
pow( mixed $num, mixed $exponent ): int|float|object
Parameters
num
The base to use.
exponent
The exponent.
Return
num raised to the power of exponent. If both arguments are non-negative integers and the result can be represented as an integer, the result will be returned with int type, otherwise it will be returned as a float.
PHP-Extensions may override the behaviour of this operation and make it return an object.
Examples
1 · int
<? $num = 2; $exponent = 4; $return = pow($num, $exponent); var_dump($return); ?>
int(16)
2 · float
<? $num = 2; $exponent = -4; $return = pow($num, $exponent); var_dump($return); ?>
float(0.0625)
3 · object
<? $num = new GMP("2"); $exponent = new GMP("4"); $return = pow($num, $exponent); var_dump($return); ?>
object(GMP)#3 (1) { ["num"]=> string(2) "16" }
4 · ** · int
<? $num = 2; $exponent = 4; $return = $num ** $exponent; var_dump($return); ?>
int(16)
5 · ** · float
<? $num = 2; $exponent = -4; $return = $num ** $exponent; var_dump($return); ?>
float(0.0625)
6 · ** · object
<? $num = new GMP("2"); $exponent = new GMP("4"); $return = $num ** $exponent; var_dump($return); ?>
object(GMP)#3 (1) { ["num"]=> string(2) "16" }