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 std.atan2 #1119

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

Conversation

CertainLach
Copy link
Contributor

Fixes: #1118

@@ -109,6 +109,7 @@ local html = import 'html.libsonnet';
<ul><code>std.asin(x)</code></ul>
<ul><code>std.acos(x)</code></ul>
<ul><code>std.atan(x)</code></ul>
<ul><code>std.atan2(y, x)</code></ul>
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Not sure about this part, it should probably go to the rest of std functions, because it was not-existant, yet rest of the math functions are defined here, because they are builtins.
Although it won't be used very often, so it's okay to skip availableSince discoverability?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Agree with the location, but IMHO we should include a note mentioning when it was added. It doesn't have to be put into the availableSince field, I think we can just include a parenthetical note in the text on this line. e.g.,

<ul><code>std.atan2(y, x)</code> (available since 0.21.0)</ul>

There are some other places (e.g., functions only available in Go) where that information is just in text in the description, not in the structured data, so I think just including version in the description text here is fine.

Copy link
Collaborator

@johnbartholomew johnbartholomew left a comment

Choose a reason for hiding this comment

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

Hi! Thanks for your patience on this. This seems like a good thing to add!

I would personally prefer this to be implemented as a builtin using libc atan2, primarily because floating point calculations can have tricky boundary conditions and precision issues (not even considering the weird numbers like NaNs and infinities), and I'm not expert enough to assess whether there are any such problems here. I mean, this implementation is probably totally fine, but even quite simple functions like hypot can be tricky to implement robustly.

What's your opinion on this?

I do see that putting it into std.jsonnet has the advantage of covering the Go jsonnet implementation as well.

I see you already put a builtin implementation into jrsonnet (CertainLach/jrsonnet@a5b2c19)

@@ -109,6 +109,7 @@ local html = import 'html.libsonnet';
<ul><code>std.asin(x)</code></ul>
<ul><code>std.acos(x)</code></ul>
<ul><code>std.atan(x)</code></ul>
<ul><code>std.atan2(y, x)</code></ul>
Copy link
Collaborator

Choose a reason for hiding this comment

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

Agree with the location, but IMHO we should include a note mentioning when it was added. It doesn't have to be put into the availableSince field, I think we can just include a parenthetical note in the text on this line. e.g.,

<ul><code>std.atan2(y, x)</code> (available since 0.21.0)</ul>

There are some other places (e.g., functions only available in Go) where that information is just in text in the description, not in the structured data, so I think just including version in the description text here is fine.

@johnbartholomew
Copy link
Collaborator

@CertainLach Any response to my previous comment?

How would you feel about implementing this as a builtin instead?

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.

add atan2 to std
2 participants