bcsqrt


php128 apg

GET the square root of an arbitrary precision number.





This function returns Warning or Fatal error if $num < 0.

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 bcsqrt 
string $num, ?int $scale null )


where,

$num The operand as STRING

$scale 
The number of decimal places 
                                to be considered in this operation

?>
 

$num


The operand treated as STRING.



$scale


The number of decimal places to be considered.

This is nullable as of PHP 8.0.XX.



  1 EXERCISE   

<?php

function sqroot ($op01$sc01)
{
if(
$op01 0)
{
    echo 
'Square root of negative numbers is not defined.<br>';
}

{
    echo 
'bcsqrt( ' $op01 ', ' $sc01 ' ) = '
                                    
var_dump(bcsqrt$op01$sc01));
                                    echo 
'<br><br>';
}
}

sqroot(M_PI10);

sqroot(56);

sqroot('5'6);

sqroot(-54);

sqroot(M_E8);

sqroot(00);

?>