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

feat: improve accuracy for atan2(y,x) when x is near-zero #19

Merged
merged 1 commit into from
Jul 25, 2021

Conversation

MikeLankamp
Copy link
Owner

atan2(y,x) requires a lot of bits in the integer part when x is near-zero. This is because atan2(y,x) does atan(y/x) internally and y/x easily overflows for very small x unless you have more integer bits than fraction bits.
However, atan(q) does 1/q if q > 1, thereby inverting the original division in atan2. So this overflow can be avoided if these divisions are shortcut.

Closes #18

`atan2(y,x)` requires a lot of bits in the integer part when `x` is near-zero. This is because `atan2(y,x)` does `atan(y/x)` internally and `y/x` easily overflows for very small `x` unless you have more integer bits than fraction bits.
However, `atan(q)` does `1/q` if `q > 1`, thereby inverting the original division in `atan2`. So this overflow can be avoided if these divisions are shortcut.

Closes #18
@MikeLankamp MikeLankamp merged commit 8b488e3 into master Jul 25, 2021
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.

Improve accuracy for atan2(y,x) with near-zero x
1 participant