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
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions doc/_stdlib_gen/stdlib-content.jsonnet
Original file line number Diff line number Diff line change
Expand Up @@ -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.

<ul><code>std.round(x)</code></ul>
<ul><code>std.isEven(x)</code></ul>
<ul><code>std.isOdd(x)</code></ul>
Expand Down
16 changes: 16 additions & 0 deletions stdlib/std.jsonnet
Original file line number Diff line number Diff line change
Expand Up @@ -1785,4 +1785,20 @@ limitations under the License.
sha3(str):: go_only_function,

trim(str):: std.stripChars(str, ' \t\n\f\r\u0085\u00A0'),

atan2(y, x)::
local pi = std.acos(-1);
if x > 0 then
std.atan(y / x)
else if x < 0 && y >= 0 then
std.atan(y / x) + pi
else if x < 0 && y < 0 then
std.atan(y / x) - pi
else if x == 0 && y > 0 then
pi / 2
else if x == 0 && y < 0 then
-pi / 2
else
0
,
}