hypot


php128 apg

CALCULATE the length of the hypotenuse of a right-angle triangle.

Compatible with LOCALE only, up to PHP 7.4.XX.





This function returns the hypotenuse length of a right-angle triangle with sides $x and $y.

The same result as:

sqrt($x**2 + $y**2)



<?php

float hypot 
( float $x , float $y )


where,

$x = The length of the first side

$y 
= The length of the second side

?>
 

$x


The length of the first side.



$y


The length of the second side.



  1 EXERCISE   

<?php

$x 
= 30;

$y = 40;


$h01a = hypot($x, $y);

$h01b = sqrt($x**2 + $y**2);

/*

The same as:

$h01b = sqrt($x*$x + $y*$y);

*/

if($h01a == $h01b)
{
    echo 
'Both values are equal!<br><br>';
    echo 
'hypot( ' . $x . ', ' . $y . ' ) = ' . $h01a . '<br><br>';
    echo  
'sqrt( ' . $x . '**2 + ' . $y . '**2 ) = ' . $h01b . '<br><br>';
}
else
{
    echo 
'Both values are different!<br><br>';
    echo 
$h01a . ' &ne; ' . $h01b . '<br><br>';
}

?> 

 RESULT   

Both values are equal!

hypot( 30, 40 ) = 50

sqrt( 30**2 + 40**2 ) = 50



  2 EXERCISE   

<?php

// setlocale(LC_ALL, 'de_DE', 'de-DE');

$x = M_PI;

$y = 2*M_PI;

$h01a = hypot($x, $y);

echo 
'hypot( ' . $x . ', ' . $y . ' ) =<br>= ' . $h01a;

?>