<?php
int|float|object pow ( mixed $num, mixed $exponent )
where,
$num = The number treated as base
$exponent = Another number treated as expoent
?>
<?php
$base = M_PI;
$exp = M_E;
$base2exp_a = pow($base, $exp);
$base2exp_b = $base**$exp;
setlocale(LC_ALL, "de_DE.utf-8", "de-DE.utf-8", "de-DE", "de");
echo 'pow(' . $base . ', ' . $exp . ') = ' . $base2exp_a . '<br><br>';
echo 'The same as ( ' . $base . ' ** ' . $exp . ' ) = ' .
$base2exp_b . '<br>';
?>
<?php
$base02 = 2.3456;
$exp02 = -19.5;
$base2exp_a = pow($base02, $exp02);
$base2exp_b = $base02**$exp02;
// Compatible with LOCALE only, up to PHP 7.4.XX
setlocale(LC_ALL, "de_DE.utf-8", "de-DE.utf-8","nds",
"nds_DE", "de-DE", "de");
echo 'pow(' . $base02 . ', ' . $exp02 . ') = ' . $base2exp_a . '<br><br>';
echo 'The same as ( ' . $base02 . ' ** ' . $exp02 . ' ) = ' .
$base2exp_b . '<br>';
?>
<?php
$base03a = M_PI;
$exp03a = 1/5;
$ex03b = 5;
$pow03a = pow($base03a, $exp03a);
// fifth root of M_PI
echo 'pow( ' . $base03a . ', ' . $exp03a . ') = ' . $pow03a . '<br><br><br>';
echo 'This leads us to reverse operation:<br><br>';
$pow03b = pow($pow03a, 5);
// fifth root of M_PI raised to the fifth power
echo 'pow( ' . $pow03a . ', ' . $ex03b . ') = ' . $pow03b . '<br><br>';
?>
<?php
$large_exp = 20000;
echo "The following all result in INF:<br>";
var_dump(pow(24, $large_exp));
echo '<br><br>';
var_dump(pow(0.24, -$large_exp));
echo '<br><br>';
var_dump(pow(-0.24, -$large_exp));
echo '<br><br>';
echo "<br><br>The following all result in 0:<br>";
var_dump(pow(0.24, $large_exp));
echo '<br><br>';
var_dump(pow(-0.24, $large_exp));
echo '<br><br>';
var_dump(pow(24, -$large_exp));
echo '<br><br>';
var_dump(pow(-24, -$large_exp));
echo '<br><br>';
echo "<br><br>The following all result in -0:<br>";
var_dump(pow(-0.24, $large_exp+1));
echo '<br><br>';
echo "<br><br>The following all result in -INF:<br>";
var_dump(pow(-24, $large_exp+1));
echo '<br><br>';
var_dump(pow(-0.24, -$large_exp+1));
?>
<?php
setlocale(LC_ALL, [ 'pt-BR', 'pt_BR' ] );
if (PHP_INT_SIZE != 8)
die("skip this test is for 64bit platform only");
define("MAX_64Bit", 9223372036854775807);
define("MAX_32Bit", 2147483647);
define("MIN_64Bit", -9223372036854775807 - 1);
define("MIN_32Bit", -2147483647 - 1);
$longVals = array(
MAX_64Bit, MIN_64Bit, MAX_32Bit,
MIN_32Bit, MAX_64Bit - MAX_32Bit,
MIN_64Bit - MIN_32Bit,
MAX_32Bit + 1, MIN_32Bit - 1,
MAX_32Bit * 2, (MAX_32Bit * 2) + 1,
(MAX_32Bit * 2) - 1,
MAX_64Bit -1, MAX_64Bit + 1,
MIN_64Bit + 1, MIN_64Bit - 1
);
$otherVals = array(0, 1, -1, 7, 9, 65, -44,
MAX_32Bit, MIN_32Bit, MAX_64Bit, MIN_64Bit);
foreach ($longVals as $longVal) {
foreach($otherVals as $otherVal) {
echo "<br><br>Testing: $longVal, $otherVal<br>";
var_dump(pow($longVal, $otherVal));
}
}
?>