Deprecated: The each() function is deprecated. This message will be suppressed on further calls in /home/zhenxiangba/zhenxiangba.com/public_html/phproxy-improved-master/index.php on line 456
PHP: hypot - Manual
[go: Go Back, main page]

PHP
downloads | documentation | faq | getting help | mailing lists | reporting bugs | php.net sites | links | conferences | my php.net

search for in the

is_finite" width="11" height="7"/> <hexdec
Last updated: Fri, 25 Apr 2008

view this page in

hypot

(PHP 4 >= 4.0.7, PHP 5)

hypot — 直角三角形の斜辺の長さを計算する

説明

float hypot ( float $x , float $y )

hypot() は、直角をはさむ 2 辺の長さが x および y である 直角三角形の斜辺の長さ、すなわち原点と (x , y ) との距離を返します。 これは sqrt(x*x + y*y) と等価です。

パラメータ

x

最初の辺の長さ。

y

二番目の辺の長さ。

返り値

斜辺の長さを返します。



is_finite" width="11" height="7"/> <hexdec
Last updated: Fri, 25 Apr 2008
 
add a note add a note User Contributed Notes
hypot
</Life>.org
10-Aug-2006 06:56
to robinv at ecosse dot net:

hypo(a, b, c) === hypo(a, hypo(b, c))
hypo(a, b, c, d) === hypo(a, hypo(b, hypo(c, d)))
...
R. Victor Klassen
25-Jun-2005 12:03
A correct implementation of hypot( x, y ) avoids the overflow that might otherwise happen if either x or y is large enough that when squared it would overflow, but the answer is small enough not to cause overflow.
robinv at ecosse dot net
08-Jan-2004 02:18
A simpler approach would be to allow an arbitrary number of parameters. That would allow for whatever number of dimensions you want *and* it would be backwards compatible with the current implementation.

<?php

function hypo()
{
   
$sum = 0;
    foreach (
func_get_args() as $dimension) {
        if (!
is_numeric($dimension)) return -1;
       
$sum += pow($dimension, 2);
    }
    return
sqrt($sum);
}

print
hypo();          // vector in 0 dimensions, magnitude = 0.
print hypo(1);         // vector in 1 dimension,  magnitude = 1.
print hypo(3, 4);       // vector in 2 dimensions, magnitude = 5.
print hypo(2, 3, 6);     // vector in 3 dimensions, magnitude = 7.

?>

is_finite" width="11" height="7"/> <hexdec
Last updated: Fri, 25 Apr 2008
 
 
show source | credits | sitemap | contact | advertising | mirror sites