mirror of
https://github.com/storytold/gridcraft.git
synced 2026-10-31 15:48:41 +00:00
G707: enforce fixed and dollar output limits
This commit is contained in:
1 parent
11bb67386c
commit
5ed6a1b9c7
2 files changed
+30
-2
No files matched your search
@@ -394,13 +394,20 @@ fn fixed(a: &[Arg], _c: &mut dyn Ctx) -> R<Value> {
|
||||
let (r, d) = rounded(a, 2.0)?;
|
||||
let no_commas = opt_bool(a, 2, false)?;
|
||||
let body = format_fixed(r, d, !no_commas);
|
||||
if body.len() + if r < 0.0 { 1 } else { 0 } > 255 {
|
||||
return Err(CellError::Value);
|
||||
}
|
||||
text_val(if r < 0.0 { format!("-{body}") } else { body })
|
||||
}
|
||||
|
||||
fn dollar(a: &[Arg], _c: &mut dyn Ctx) -> R<Value> {
|
||||
let (r, d) = rounded(a, 2.0)?;
|
||||
let body = format_fixed(r, d, true);
|
||||
text_val(if r < 0.0 { format!("(${body})") } else { format!("${body}") })
|
||||
let out = if r < 0.0 { format!("(${body})") } else { format!("${body}") };
|
||||
if out.len() > 254 {
|
||||
return Err(CellError::Value);
|
||||
}
|
||||
text_val(out)
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------------------------
|
||||
@@ -1241,6 +1248,26 @@ mod tests {
|
||||
is_text(ev("T", vec![n(1.0)]), "");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn fixed_and_dollar_output_limits() {
|
||||
assert!(matches!(ev("FIXED", vec![n(1e191), n(0.0)]), Value::Text(ref s) if s.len() == 255));
|
||||
is_err(ev("FIXED", vec![n(1e192), n(0.0)]), CellError::Value);
|
||||
assert!(matches!(ev("FIXED", vec![n(-1e253), n(0.0), b(true)]), Value::Text(ref s) if s.len() == 255));
|
||||
is_err(ev("FIXED", vec![n(-1e254), n(0.0), b(true)]), CellError::Value);
|
||||
assert!(matches!(ev("FIXED", vec![n(1e189), n(1.0)]), Value::Text(ref s) if s.len() == 255));
|
||||
is_err(ev("FIXED", vec![n(1e190), n(1.0)]), CellError::Value);
|
||||
|
||||
assert!(matches!(ev("DOLLAR", vec![n(1e189), n(0.0)]), Value::Text(ref s) if s.len() == 254));
|
||||
is_err(ev("DOLLAR", vec![n(1e190), n(0.0)]), CellError::Value);
|
||||
assert!(matches!(ev("DOLLAR", vec![n(-1e188), n(0.0)]), Value::Text(ref s) if s.len() == 254));
|
||||
is_err(ev("DOLLAR", vec![n(-1e189), n(0.0)]), CellError::Value);
|
||||
assert!(matches!(ev("DOLLAR", vec![n(1e187), n(2.0)]), Value::Text(ref s) if s.len() == 254));
|
||||
is_err(ev("DOLLAR", vec![n(1e188), n(2.0)]), CellError::Value);
|
||||
is_err(ev("DOLLAR", vec![n(-1e187), n(2.0)]), CellError::Value);
|
||||
assert!(matches!(ev("DOLLAR", vec![n(1e189), n(-1.0)]), Value::Text(ref s) if s.len() == 254));
|
||||
is_err(ev("DOLLAR", vec![n(1e190), n(-1.0)]), CellError::Value);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn before_after() {
|
||||
is_text(ev("TEXTBEFORE", vec![t("Red riding hood"), t(" ")]), "Red");
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
# Function parity: worksheet functions and formulas
|
||||
|
||||
> **Last reviewed:** 2026-10-15 · **Last updated:** 2026-10-25 · **Change:** minor (the LAMBDA row lists the recursion limit and its `#NUM!`, and the error a defined name holding an error gives when called; earlier: number text with accounting parentheses coerces like Excel 365; INDEX with one index on a 2-D reference is #REF! as in Excel; earlier: SUBTOTAL and AGGREGATE cap the cells they visit, #2175) · **Target:** Microsoft Excel (Microsoft 365), Excel for Mac 16.113.4
|
||||
> **Last reviewed:** 2026-10-31 · **Last updated:** 2026-10-31 · **Change:** minor (FIXED refuses results over 255 characters and DOLLAR refuses results over 254, matching the signed, decimal and separator boundary checks in Windows Excel 16.0 build 20527, LCID 1033) · **Target:** Microsoft Excel (Microsoft 365), Excel for Mac 16.113.4
|
||||
|
||||
Excel's worksheet functions, category by category, against GridCraft's function library. Part of
|
||||
[target-app-parity.md](target-app-parity.md); gaps feed [gaps.md](gaps.md).
|
||||
@@ -123,6 +123,7 @@ workbooks; results checked in as data, not Excel files) and fixing what it finds
|
||||
|
||||
| Date | Change | Summary |
|
||||
|---|---|---|
|
||||
| 2026-10-31 | minor | FIXED accepts output through 255 characters; DOLLAR accepts output through 254. Windows Excel 16.0 build 20527 (LCID 1033) confirmed the distinct cutoffs with grouped and ungrouped values, signs, currency layout and decimal places |
|
||||
| 2026-10-25 | minor | LAMBDA row: a LAMBDA that calls itself more than 140 times, and a formula nested past the depth limit, give `#NUM!` (#1809; nesting gave `#CALC!` before). `=Foo(1)` where the defined name Foo holds `#N/A` gives `#N/A`, not `#NAME?` |
|
||||
| 2026-10-23 | minor | Number text coercion (VALUE, arithmetic, typed entry): a dollar sign before accounting parentheses (`$(1,234)`, `$ (5)`) and a percent sign after them (`(5)%`) read as negatives; `(-5)`, `((5))`, `($-5)`, `$5%`, `$(5)%` and dates or times in parentheses are `#VALUE!`, as observed in Excel 365 |
|
||||
| 2026-10-23 | minor | INDEX with only a row index on a reference of several rows and columns (`INDEX(A1:C3,2)`, `INDEX(A1:C3,0)`) is `#REF!`, as observed in Excel, so it also fails as a range endpoint and inside other functions; an empty column argument (`INDEX(A1:C3,2,)`) still gives the row. Checked that a column array with one index stays a 1×1 array (`TYPE` 64), which is what Excel returns |
|
||||
|
||||
Reference in new issue
Block a user