-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
Editorial: fix algorithm of Math.atan2 #3170
Conversation
a99ee7e
to
231b8c7
Compare
2c0c70f
to
759b8e1
Compare
759b8e1
to
fa87a7b
Compare
Thanks for the PR, but isn't this wrong? Consider the case in your issue: y=1, x=-1. In that case we'll have I think this ends up simplest if we do the inverse tan of the absolute value of function atan2(y, x) {
let r = Math.atan(Math.abs(y/x));
if (x > 0 && y > 0) return r;
if (x > 0 && y < 0) return -r;
if (x < 0 && y > 0) return Math.PI - r;
if (x < 0 && y < 0) return -Math.PI + r;
} @Josh-Cena want to update the PR to work like that? Otherwise I'll get to it in the next week or two. |
OK, I'll take a look. If I don't get to it in the next week or two then I probably will not ever :P |
@bakkot I realized I only need to take abs for |
@Josh-Cena That does work but I think it's significantly harder to understand than the version which just lists all four cases explicitly. Avoiding an extra negation in the spec algorithms isn't really a goal. |
9a291d2
to
648f25f
Compare
Fix #2897.
I have no idea if this meets the conventions, but I hope the idea is at least correct. Below is the output of
Math.atan2
in Node: