From a5b2c195113870d322d405c64b1111a58b06657a Mon Sep 17 00:00:00 2001 From: Yaroslav Bolyukin Date: Thu, 30 Nov 2023 21:45:36 +0100 Subject: [PATCH] feat: add std.atan2 Fixes: https://github.com/CertainLach/jrsonnet/issues/141 Fixes: https://github.com/google/jsonnet/issues/1118 --- crates/jrsonnet-stdlib/src/lib.rs | 1 + crates/jrsonnet-stdlib/src/math.rs | 5 +++++ 2 files changed, 6 insertions(+) diff --git a/crates/jrsonnet-stdlib/src/lib.rs b/crates/jrsonnet-stdlib/src/lib.rs index c5dcea12..6f1f9413 100644 --- a/crates/jrsonnet-stdlib/src/lib.rs +++ b/crates/jrsonnet-stdlib/src/lib.rs @@ -104,6 +104,7 @@ pub fn stdlib_uncached(settings: Rc>) -> ObjValue { ("asin", builtin_asin::INST), ("acos", builtin_acos::INST), ("atan", builtin_atan::INST), + ("atan2", builtin_atan2::INST), ("exp", builtin_exp::INST), ("mantissa", builtin_mantissa::INST), ("exponent", builtin_exponent::INST), diff --git a/crates/jrsonnet-stdlib/src/math.rs b/crates/jrsonnet-stdlib/src/math.rs index c1a0d54a..d124cd3c 100644 --- a/crates/jrsonnet-stdlib/src/math.rs +++ b/crates/jrsonnet-stdlib/src/math.rs @@ -89,6 +89,11 @@ pub fn builtin_atan(x: f64) -> f64 { x.atan() } +#[builtin] +pub fn builtin_atan2(y: f64, x: f64) -> f64 { + y.atan2(x) +} + #[builtin] pub fn builtin_exp(x: f64) -> f64 { x.exp()