Skip to content

Instantly share code, notes, and snippets.

@ramons03
Created July 16, 2013 15:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ramons03/6010045 to your computer and use it in GitHub Desktop.
Save ramons03/6010045 to your computer and use it in GitHub Desktop.
Here’s how to compute sqrt(x*x + y*y) without risking overflow.
max = maximum(|x|, |y|)
min = minimum(|x|, |y|)
r = min / max
return max*sqrt(1 + r*r)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment