bpo-41513: Save unnecessary steps in the hypot() calculation by rhettinger · Pull Request #21994 · python/cpython · GitHub
Skip to content

bpo-41513: Save unnecessary steps in the hypot() calculation - #21994

Merged
rhettinger merged 4 commits into
python:masterfrom
rhettinger:hypot_trimmed
Aug 29, 2020
Merged

rhettinger merged 4 commits into
python:masterfrom
rhettinger:hypot_trimmed

Conversation

@rhettinger

@rhettinger rhettinger commented Aug 28, 2020

Copy link
Copy Markdown
Contributor

Reasoning for the assertion:

  • In the loop, each scaled vector element has a magnitude less than 1.0.
  • After the Veltkamp split, lo has a maximum magnitude of 2**-27.
  • The maximum magnitude of lo squared is 2**-54.
  • 2**-54 < float_info.epsilon
  • Since csum >= 1.0 and lo ** 2 < float_info.epsilon, we have csum + lo*lo == csum

Note that outside of the loop, that chain of reasoning fails. Unlike scaled vector elements, h can be greater than 1.0, so after hi, lo = split(h), the lo * lo term can be greater than epsilon.

https://bugs.python.org/issue41513

@tim-one

tim-one commented Aug 29, 2020

Copy link
Copy Markdown
Member

@rhettinger
rhettinger merged commit 27de286 into python:master Aug 29, 2020
@bedevere-bot

Copy link
Copy Markdown

@rhettinger: Please replace # with GH- in the commit message next time. Thanks!

@bedevere-bot

bedevere-bot commented Aug 29, 2020

Copy link
Copy Markdown

xzy3 pushed a commit to xzy3/cpython that referenced this pull request Oct 18, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants