mirror of
https://github.com/storytold/wordcraft.git
synced 2026-10-30 05:17:25 -06:00
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:
co-authored by
Claude Haiku 5.5
parent
fd0bb2fb1e
commit
9371cb0536
@@ -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)));
|
||||
|
||||
Reference in New Issue
Block a user