Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Write dig-deeper page for darts and talk about hypot #660

Open
cmcaine opened this issue Aug 25, 2023 · 0 comments
Open

Write dig-deeper page for darts and talk about hypot #660

cmcaine opened this issue Aug 25, 2023 · 0 comments

Comments

@cmcaine
Copy link
Contributor

cmcaine commented Aug 25, 2023

There's a cool paper here that details how Julia got a new algorithm for hypot that's much better than the old one and quite a lot better than the version that's in libm.

https://arxiv.org/pdf/1904.09481.pdf

Also worth talking about how you can work with radius^2. And some explanation of why doing these kinds of calculations with floats is generally safer than using ints to try and counteract the common fear of floats and complacency about integers.

It would be neat to explain a bit about precision, but I am bad at numerical analysis. I think if you use a fused multiply add to find the radius squared then you get two sources of error like this:

y2 = yyd1
r2 = fma(x, x, y2)*d2

where -eps/2 <= d1, d2 <= eps/2

So a final max theoretical error is something like: (eps/2)(xx + yy(eps/2)) . Which seems pretty small.

Mostly just for me, but the paper includes some corrections that I would like to understand. I think it's plausible that a number closer to the magnitude of the input variables can retain more precision than the sum of the squares of those input variables, so maybe the hypot function produces a value with higher theoretical precision?

Anyway, I can certainly recreate their experiments and find the experimental error for a variety of inputs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant