➜

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.

作者 rhettinger
收信人 mark.dickinson, rhettinger, serhiy.storchaka, tim.peters
日期 2020-08-10.01:14:14
SpamBayes Score -1.0
Marked as misclassified 是
Message-id <1597022054.77.0.549983904563.issue41513@roundup.psfhosted.org>
In-reply-to
内容
I'd like to resurrect Serhiy's idea for using power-of-two scaling in math.hypot() rather than dividing each coordinate by the maximum value.

I drafted a patch.  It looks to be a little faster than what we have now and is generally (but not always) more accurate.

For accuracy, the current approach has the advantage that for the largest coordinate, (x/max)**2 is exactly 1.0.   If that element is much larger than the others, it overpowers the 1/2 ulp error in each of the other divisions.

In contrast, scaling by a power of two is always exact, but the squaring of the largest scaled coordinate is no longer exact.

The two approaches each have some cases that are more accurate than the other.  I generated 10,000 samples.  In 66% of the cases, the two results agree.  In 26% of the cases, scaling by a power of two was more accurate.  In the remaining 8%, the division by max was more accurate.   The standard deviation of relative errors was better using power-of-two scaling.  These results were consistent whether using 2, 3, or 20 dimensions.

As expected, multiplying by a power of two was a bit faster than dividing by an arbitrary float.
历史
日期 用户 动作 参数
2020-08-10 01:14:14rhettinger修改recipients: + rhettinger, tim.peters, mark.dickinson, serhiy.storchaka
2020-08-10 01:14:14rhettinger修改messageid: <1597022054.77.0.549983904563.issue41513@roundup.psfhosted.org>
2020-08-10 01:14:14rhettinger链接issue41513 messages
2020-08-10 01:14:14rhettinger创建