From a8d47a8bb6ac4477ff43a8bbfb84d9ebac625fc7 Mon Sep 17 00:00:00 2001 From: Yaroslav Bolyukin Date: Thu, 30 Nov 2023 22:02:25 +0100 Subject: [PATCH] feat: add std.atan2 Fixes: https://github.com/google/jsonnet/issues/1118 --- stdlib/std.jsonnet | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/stdlib/std.jsonnet b/stdlib/std.jsonnet index a843d3a08..3cfeab986 100644 --- a/stdlib/std.jsonnet +++ b/stdlib/std.jsonnet @@ -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 + , }