Edit report at http://bugs.php.net/bug.php?id=52734&edit=1

 ID:                 52734
 Updated by:         [email protected]
 Reported by:        a at b dot c dot de
 Summary:            Extend hypot() to three dimensions
-Status:             Open
+Status:             Wont fix
 Type:               Feature/Change Request
 Package:            Math related
 Operating System:   Windows XP
 PHP Version:        5.3.3
 Block user comment: N

 New Comment:

hypot() was intended to be (and is generally implemented as) a wrapper
for the C99 and POSIX hypot() function, which itself only accepts two
dimensions. Given that this can be easily implemented in PHP itself
using sqrt() (as you demonstrate), I don't see any real benefit in
diverging from the underlying implementation.


Previous Comments:
------------------------------------------------------------------------
[2010-08-30 06:50:00] a at b dot c dot de

Description:
------------
The existing hypot() function is limited to finding the hypotenuse of a
right-angled triangle in two dimensions ($h = hypot($x,$y)), when in
fact it is well-defined for higher dimensions as well as the length of
the diagonal of a (hyper)cuboid with edge lengths $x,$y,$z...; it's the
square root of the sum of the squares of the edge lengths.



For geometric purposes it would be helpful to have at least
hypot($x,$y,$z). The existing alternatives are sqrt($x*$x+$y*$y+$z*$z)
or hypot(hypot($x,$y),$z). The latter is (not surprisingly) markedly
slower, and also less accurate.

Test script:
---------------
function length($v1, $v2)

{

    return hypot($v1[0]-$v2[0], $v1[1]-$v2[1], $v1[2]-$v2[2]);

}



$v1 = array(1, 1, 1);

$v2 = array(5, 6, 1);

echo length($v1, $v2);



Expected result:
----------------
6.4031242374328

Actual result:
--------------
A warning about hypot expecting exactly two parameters, and a NULL
return value.


------------------------------------------------------------------------



-- 
Edit this bug report at http://bugs.php.net/bug.php?id=52734&edit=1

Reply via email to