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

Add math.atan2 #819

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft

Add math.atan2 #819

wants to merge 1 commit into from

Conversation

gordonbondon
Copy link

No description provided.

@gordonbondon gordonbondon marked this pull request as draft November 14, 2024 17:56
@Specialization
protected double eval(VmTyped self, long x, double y) {
return StrictMath.atan2(x, y);
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Need to handle all permutations of long and double here:

Suggested change
}
}
@Specialization
protected double eval(VmTyped self, double x, double y) {
return StrictMath.atan2(x, y);
}
@Specialization
protected double eval(VmTyped self, double x, long y) {
return StrictMath.atan2(x, y);
}

@@ -130,6 +130,10 @@ examples {
math.atan(math.tan(-2.34))
}

["atan2"] {
math.atan2(4, -3)
Copy link
Contributor

@bioball bioball Nov 14, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's add some more examples that exercise all permutations.

Suggested change
math.atan2(4, -3)
math.atan2(4, -3)
math.atan2(4.5, -3.5)
math.atan2(4.5, -3)
math.atan2(4, 3.5)

Also: maybe a test for correspondence with PI, in the facts section:

facts {
  ["atan2"] {
    math.atan2(1, 0) == math.pi / 2
    math.atan2(0, -1) == math.pi
  }
}

Comment on lines +148 to +150
/// Returns the [4-quadrant inverse tangent][1] of [x] and [y].
///
/// [1]: https://en.wikipedia.org/wiki/Atan2
Copy link
Contributor

@bioball bioball Nov 14, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since we're linking to Wikipedia, let's use verbiage that aligns with it.

Also, need a @Since annotation.

Suggested change
/// Returns the [4-quadrant inverse tangent][1] of [x] and [y].
///
/// [1]: https://en.wikipedia.org/wiki/Atan2
/// Returns the [2-argument arctangent][1] of [x] and [y].
///
/// [1]: https://en.wikipedia.org/wiki/Atan2
@Since { version = "0.28.0" }

It might also be helpful to have one more paragraph to describe this function's purpose. Maybe something like: "The result is 𝜃 (theta) when converting cartesian coordinates 𝑥 and 𝑦 to polar coordinates 𝑟 and 𝜃."

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.

2 participants