bcpow


php128 apg

RAISE an arbitrary precision number to another.





This function returns the ( $num ** $exponent ), as STRING.

The interval range of valid $exponent is, at least: [ -2147483648, 2147483647 ] and, it is platform specific.

Since PHP 7.3.0 this function return numbers with the requested scale.

Previously, the returned numbers may have omitted trailing decimal zeros.

If $scale is omited, this function will default to the scale set globally with the bcscale function, or fallback to 0 if this has not been set.



<?php

string bcpow 
( string $num, 
                       
string $exponent, 
                          ?
int $scale = null )


where,

$num = The base as STRING

$exponent 
= The exponent as STRING

$scale 
= The number of decimal places 
                                       considered by this operation

?>
 

$num


The base treated as STRING.



$exponent


The exponent treated as STRING.



$scale


The number of decimal places to be considered.

This is nullable as of PHP 8.0.XX.



  1 EXERCISE   

<?php

$vl01a 
= 2020.106;

$vl01b = 2;

$sc01a = 4;

$sc01b = 10;

$bca01a = bcpow($vl01a, $vl01b);

$bca01b1 = bcpow($vl01a, $vl01b, $sc01a);

$bca01b2 = bcpow($vl01a, $vl01b, $sc01b);

echo 
'bcpow( ' . $vl01a . ', ' . $vl01b . ' ) = ' . $bca01a . 
                                    
'<br>[ NO SCALE IS PROVIDED ]<br><br>'; 

echo 
'bcpow( ' . $vl01a . ', ' . $vl01b  . ', ' . $sc01a . ' ) = ' . $bca01b1 . 
                                    
'<br>[ SCALE = ' . $sc01a . ' ]<br><br>';

echo 
'bcpow( ' . $vl01a . ', ' . $vl01b  . ', ' . $sc01b . ' ) = ' . $bca01b2 . 
                                    
'<br> [ SCALE = ' . $sc01b . ' ]<br><br>';

?> 

 RESULT   

bcpow( 2020.106, 2 ) = 4080828
[ NO SCALE IS PROVIDED ]

bcpow( 2020.106, 2, 4 ) = 4080828.2512
[ SCALE = 4 ]

bcpow( 2020.106, 2, 10 ) = 4080828.2512360000
[ SCALE = 10 ]