Skip to content

Commit

Permalink
feat: add std.atan2
Browse files Browse the repository at this point in the history
  • Loading branch information
CertainLach committed Nov 30, 2023
1 parent 0679858 commit a22be2f
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
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>
<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
,
}

0 comments on commit a22be2f

Please sign in to comment.