Skip to content

Conversation

@deepsource-autofix
Copy link

Calculating the length of the hypotenuse using the standard formula c = sqrt(a**2 + b**2) may lead to overflow if the two other sides are both very large. Even though c will not be much bigger than max(a, b), either a**2 or b**2 (or both) could be. Thus, the calculation could overflow, even though the result is well within representable range. It is recommended to use the built-in function hypot(a,b) from the math library.

Calculating the length of the hypotenuse using the standard formula `c = sqrt(a**2 + b**2)` may lead to overflow if the two other sides are both very large. Even though `c` will not be much bigger than `max(a, b)`, either `a**2` or `b**2` (or both) could be. Thus, the calculation could overflow, even though the result is well within representable range. It is recommended to use the built-in function `hypot(a,b)` from the `math` library.
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

Successfully merging this pull request may close these issues.

1 participant