This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author steven.daprano
Recipients mark.dickinson, rhettinger, skrah, steven.daprano, tim.peters
Date 2018-03-17.00:27:53
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1521246473.48.0.467229070634.issue33089@psf.upfronthosting.co.za>
In-reply-to
Content
The obvious work-around of calling hypot multiple times is not only tedious, but it loses precision. For example, the body diagonal through a 1x1x1 cube should be √3 exactly:

py> from math import hypot, sqrt
py> hypot(hypot(1, 1), 1) == sqrt(3)
False


I know of at least five languages or toolkits which support this feature, or something close to it: Javascript, Julia, Matlab, GNU Scientific Library, and C++.

Javascript and Julia support arbitrary numbers of arguments:

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/hypot

https://github.com/JuliaLang/julia/pull/15649

Using Firefox's javascript console, I get the correct body diagonal for the cube:

>> Math.hypot(1, 1, 1) == Math.sqrt(3)
true


Matlab's hypot() function only takes two arguments, but norm(vector) returns the Euclidean 2-norm of the vector, i.e. equivalent to the hypot of multiple arguments.

https://au.mathworks.com/help/matlab/ref/norm.html

The GNU Scientific Library and C++ support a three-argument form of hypot:

http://git.savannah.gnu.org/cgit/gsl.git/commit/?id=e1711c84f7ba5c2b22d023dcb7e10810233fff27

http://en.cppreference.com/w/cpp/numeric/math/hypot
http://open-std.org/JTC1/SC22/WG21/docs/papers/2015/p0030r1.pdf


So +1 on math.hypot supporting arbitrary number of arguments.
History
Date User Action Args
2018-03-17 00:27:53steven.dapranosetrecipients: + steven.daprano, tim.peters, rhettinger, mark.dickinson, skrah
2018-03-17 00:27:53steven.dapranosetmessageid: <1521246473.48.0.467229070634.issue33089@psf.upfronthosting.co.za>
2018-03-17 00:27:53steven.dapranolinkissue33089 messages
2018-03-17 00:27:53steven.dapranocreate