|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2010-08-31 10:15 UTC] aharvey@php.net
-Status: Open
+Status: Wont fix
[2010-08-31 10:15 UTC] aharvey@php.net
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Mon Nov 17 09:00:01 2025 UTC |
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.