gmp_sqrtrem


gmp apg

CALCULATES the integer portion of the square root of a GMP number and the remainder.





This function returns an ARRAY where the first element is the integer portion of the square root of $num and the second is the remainder, this is the diference between $num and the first element squared.

This function is valid, only, for $num > 0 or $num = 0.



<?php

array gmp_sqrtrem ( GMP|int|string $num )


where,

$num = GMP number to obtain the INTEGER portion 
                                          of square root with remainder

?>
 

$num


The GMP number to obtain the integer portion of square root with remainder.



  1 EXERCISE   

<?php

function intptsqrtrem01 ( $a01 )
{
    
$sqr01 = gmp_sqrtrem($a01);

echo 
$sqr01[0] . ' is the integer portion of square root of ' . 
$a01 . '<br>';
echo 
'and ' . $sqr01[1] . ' is the remainder.<br><br>';

}

$a01a = [ '0200000', '0200001', 
                       
'0x10000', '0x1000A', 
                               
65536, 65537, 200, 
                                        
'023', '0x13', 
                                        
0, 2, 4, 16, 19, 210 ];

foreach(
$a01a as $a01)
{
intptsqrtrem01($a01);
}    

?> 

  2 EXERCISE   

<?php

function intptsqrtrem02 ( $a02 )
{
    
$sqr02 = gmp_sqrtrem($a02);

echo 
$sqr02[0] . ' is the integer portion of square root of ' . 
$a02 . '<br>';
echo 
'and ' . $sqr02[1] . ' is the remainder.<br><br>';

}

$a02a = [ -2, -4, -16, -19, -210 ];

foreach(
$a02a as $a02)
{
intptsqrtrem02($a02);
}    

?>