php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login go to bug id or search bugs for
Request #52734 Submitted: Extend hypot() to three dimensions 2010-08-30 06:50 UTC 2010-08-31 10:15 UTC a at b dot c dot de Wont fix Math related 5.3.3 Windows XP No None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If this is not your bug, you can add a comment by following this link.

[2010-08-30 06:50 UTC] 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.

```

## Pull Requests

Add a Pull Request

## History

[2010-08-31 10:15 UTC] aharvey@php.net
-Status: Open +Status: Wont fix
[2010-08-31 10:15 UTC] aharvey@php.net
```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.
```
 Copyright © 2001-2019 The PHP Group All rights reserved. Last updated: Mon Sep 23 11:01:27 2019 UTC