Skip to content

Commit 202e376

Browse files
committed
fix: use SQL param order for ATAN2
1 parent 8472254 commit 202e376

2 files changed

Lines changed: 9 additions & 3 deletions

File tree

specs/query-language.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ Each parameter can be either a constant, field name, or a JSONPath expression.
144144
- `SQRT(x)`: Returns the square root of `x`
145145

146146
##### Binary Functions
147-
- `ATAN2(x, y)`: Returns the arc tangent of `y/x` in radians
147+
- `ATAN2(y, x)`: Returns the arc tangent of `y/x` in radians
148148
- `DIV(x, y)`: Returns the integer quotient of `x/y`
149149
- `LOG(x, y)`: Returns the logarithm of `x` with base `y` (`y` is optional and defaults to e)
150150
- `LOG10(x)`: Returns the base-10 logarithm of `x`

src/expression.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -307,7 +307,7 @@ fn evaluate_function(func: &ScalarFunction, vals: &[Value]) -> Value {
307307
None
308308
};
309309
match (f1, f2) {
310-
(Some(x), Some(y)) => Some(y.atan2(x)),
310+
(Some(y), Some(x)) => Some(y.atan2(x)),
311311
_ => None,
312312
}
313313
}
@@ -569,13 +569,19 @@ mod tests {
569569
);
570570

571571
// ATAN2(1, 1) -> pi/4
572-
// ATAN2(x, y) = atan(y/x).
572+
// ATAN2(y, x) = atan(y/x).
573573
// args: [one, one]. atan(1/1) = atan(1) = pi/4
574574
let atan2_val = eval_args(ScalarFunction::Atan2, vec!["one", "one"])
575575
.as_f64()
576576
.unwrap();
577577
assert!((atan2_val - std::f64::consts::FRAC_PI_4).abs() < 1e-10);
578578

579+
// ATAN2(1, 0) -> pi/2 (Y=1, X=0)
580+
let atan2_val_2 = eval_args(ScalarFunction::Atan2, vec!["one", "zero"])
581+
.as_f64()
582+
.unwrap();
583+
assert!((atan2_val_2 - std::f64::consts::FRAC_PI_2).abs() < 1e-10);
584+
579585
// ROUND
580586
// ROUND(0.5) -> 1.0
581587
assert_eq!(

0 commit comments

Comments
 (0)