Return 0 for SIGN(0) in table formulas

Found while testing crates/engine/src/cmd/table_formula.rs:721

Co-Authored-By: Claude Haiku 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
NetterSilver
2026-10-15 14:44:40 +00:00
co-authored by Claude Haiku 5.5
parent fd0bb2fb1e
commit 9371cb0536
+14 -1
View File
@@ -718,7 +718,10 @@ fn call(name: &str, args: &[Expr], here: &Here) -> Result<f64, CmdError> {
}
"ABS" => Ok(one(name, args, here)?.abs()),
"INT" => Ok(one(name, args, here)?.floor()),
"SIGN" => Ok(one(name, args, here)?.signum()),
"SIGN" => {
let x = one(name, args, here)?;
Ok(if x == 0.0 { 0.0 } else { x.signum() })
}
"ROUND" => match args {
[a, b] => {
let x = scalar(eval(a, here)?)?;
@@ -763,6 +766,16 @@ mod tests {
evaluate(t, r, c, f)
}
#[test]
fn sign_of_zero_is_zero() {
let t = table(&[&["0", "5", "-5"]]);
assert_eq!(ev(&t, 0, 0, "=SIGN(0)"), Ok(0.0));
assert_eq!(ev(&t, 0, 0, "=SIGN(-0)"), Ok(0.0));
assert_eq!(ev(&t, 0, 1, "=SIGN(A1)"), Ok(0.0), "a cell holding 0");
assert_eq!(ev(&t, 0, 0, "=SIGN(5)"), Ok(1.0));
assert_eq!(ev(&t, 0, 0, "=SIGN(-5)"), Ok(-1.0));
}
#[test]
fn cell_references_count_from_one_and_from_a() {
assert_eq!(cell_ref("A1"), Some((0, 0)));