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 rhettinger
Recipients mark.dickinson, rhettinger, serhiy.storchaka, tim.peters
Date 2020-08-14.22:54:06
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1597445646.68.0.05367263867.issue41513@roundup.psfhosted.org>
In-reply-to
Content
> While we're doing this, any chance we could special-case 
> the two-argument hypot to use the libm hypot directly? 

Yes, that is an easy amendment (see below).

I just tried it out on the macOs build but didn't see a change in accuracy from the current PR which uses lossless power-of-two-scaling and Neumaier summation.

In GCC's libquadmath implementation, the comments say that the error is less than 1 ulp, falling short of being correctly rounded within ±½ ulp.

If the platform hypots have the nearly the same accuracy as the current PR, it may make sense to skip the special case and opt for consistent cross-platform results.

==================================================================

$ git diff
diff --git a/Modules/mathmodule.c b/Modules/mathmodule.c
index d0621f59df..3a42ea5318 100644
--- a/Modules/mathmodule.c
+++ b/Modules/mathmodule.c
@@ -2457,6 +2457,10 @@ vector_norm(Py_ssize_t n, double *vec, double max, int found_nan)
     if (max == 0.0 || n <= 1) {
         return max;
     }
+    if (n == 2) {
+        /* C library hypot() implementations tend to be very accurate */
+        return hypot(vec[0], vec[1]);
+    }
     frexp(max, &max_e);
     if (max_e >= -1023) {
         scale = ldexp(1.0, -max_e)

$ gcc --version
Configured with: --prefix=/Applications/Xcode.app/Contents/Developer/usr --with-gxx-include-dir=/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/c++/4.2.1
Apple clang version 11.0.3 (clang-1103.0.32.62)
Target: x86_64-apple-darwin19.6.0
Thread model: posix
InstalledDir: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin

$ ./python.exe test_hypot.py

======== 2 dimensions ========
platform hypot():	[(-1.0, 8398), (0.0, 83152), (1.0, 8450)]
scaled-by-2     :	[(-1.0, 8412), (0.0, 83166), (1.0, 8422)]
History
Date User Action Args
2020-08-14 22:54:06rhettingersetrecipients: + rhettinger, tim.peters, mark.dickinson, serhiy.storchaka
2020-08-14 22:54:06rhettingersetmessageid: <1597445646.68.0.05367263867.issue41513@roundup.psfhosted.org>
2020-08-14 22:54:06rhettingerlinkissue41513 messages
2020-08-14 22:54:06rhettingercreate