mirror of
https://github.com/storytold/gridcraft.git
synced 2026-10-30 21:56:53 -06:00
@@ -62,6 +62,15 @@ fn format_base(v: i64, radix: u32, places: Option<f64>) -> R<Value> {
|
||||
if v < min || v > max {
|
||||
return Err(CellError::Num);
|
||||
}
|
||||
let places = places
|
||||
.map(|p| {
|
||||
let p = p.trunc();
|
||||
if !(1.0..=10.0).contains(&p) {
|
||||
return Err(CellError::Num);
|
||||
}
|
||||
Ok(p as usize)
|
||||
})
|
||||
.transpose()?;
|
||||
if v < 0 {
|
||||
let u = v + (1i64 << bits);
|
||||
return text_val(to_radix(u, radix));
|
||||
@@ -70,11 +79,6 @@ fn format_base(v: i64, radix: u32, places: Option<f64>) -> R<Value> {
|
||||
match places {
|
||||
None => text_val(s),
|
||||
Some(p) => {
|
||||
let p = p.trunc();
|
||||
if !(1.0..=10.0).contains(&p) {
|
||||
return Err(CellError::Num);
|
||||
}
|
||||
let p = p as usize;
|
||||
if s.len() > p {
|
||||
return Err(CellError::Num);
|
||||
}
|
||||
@@ -97,7 +101,13 @@ fn to_radix(mut v: i64, radix: u32) -> String {
|
||||
}
|
||||
|
||||
fn places_arg(a: &[Arg]) -> R<Option<f64>> {
|
||||
if has(a, 1) { Ok(Some(num(a, 1)?)) } else { Ok(None) }
|
||||
if !has(a, 1) {
|
||||
return Ok(None);
|
||||
}
|
||||
if matches!(a.get(1).map(scalar), Some(Value::Bool(_))) {
|
||||
return Err(CellError::Value);
|
||||
}
|
||||
Ok(Some(num(a, 1)?))
|
||||
}
|
||||
|
||||
fn convert_base(a: &[Arg], from: u32, to: u32) -> R<Value> {
|
||||
@@ -402,6 +412,12 @@ mod tests {
|
||||
is_text(ev("BIN2OCT", vec![n(1111111111.0)]), "7777777777");
|
||||
is_text(ev("DEC2BIN", vec![n(9.0), n(4.0)]), "1001");
|
||||
is_text(ev("DEC2BIN", vec![n(-100.0)]), "1110011100");
|
||||
is_err(ev("DEC2BIN", vec![n(-1.0), n(0.0)]), CellError::Num);
|
||||
is_err(ev("DEC2HEX", vec![n(-1.0), n(11.0)]), CellError::Num);
|
||||
is_err(ev("DEC2OCT", vec![n(-1.0), n(-1.0)]), CellError::Num);
|
||||
is_err(ev("DEC2BIN", vec![n(1.0), crate::Arg::val(Value::Bool(true))]), CellError::Value);
|
||||
is_text(ev("DEC2BIN", vec![n(-1.0), n(1.0)]), "1111111111");
|
||||
is_text(ev("DEC2HEX", vec![n(-1.0), n(10.0)]), "FFFFFFFFFF");
|
||||
is_err(ev("DEC2BIN", vec![n(512.0)]), CellError::Num);
|
||||
is_text(ev("DEC2HEX", vec![n(100.0), n(4.0)]), "0064");
|
||||
is_text(ev("DEC2HEX", vec![n(-54.0)]), "FFFFFFFFCA");
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
# Function parity: worksheet functions and formulas
|
||||
|
||||
> **Last reviewed:** 2026-10-31 · **Last updated:** 2026-10-31 · **Change:** minor (base conversion rejects surrounding whitespace in source strings, as observed in Excel; earlier: ECMA.CEILING listed with USDOLLAR as not on Microsoft's list; IMSQRT reproduces Excel's stray real part for negative reals) · **Target:** Microsoft Excel (Microsoft 365), Excel for Mac 16.113.4
|
||||
> **Last reviewed:** 2026-10-31 · **Last updated:** 2026-10-31 · **Change:** minor (base-conversion places are validated for negative inputs and reject Boolean arguments, as observed in Excel; earlier: base conversion rejects surrounding whitespace in source strings, as observed in Excel; earlier: ECMA.CEILING listed with USDOLLAR as not on Microsoft's list; IMSQRT reproduces Excel's stray real part for negative reals) · **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).
|
||||
@@ -125,6 +125,7 @@ workbooks; results checked in as data, not Excel files) and fixing what it finds
|
||||
| Date | Change | Summary |
|
||||
|---|---|---|
|
||||
| 2026-10-31 | minor | BIN2*, HEX2* and OCT2* reject surrounding spaces and tabs in source strings with `#NUM!`, matching Excel; plain unpadded values remain valid |
|
||||
| 2026-10-31 | minor | DEC2BIN, DEC2HEX and DEC2OCT validate `places` before returning negative two's-complement output, and Boolean places return `#VALUE!`, matching Excel |
|
||||
| 2026-10-27 | minor | ECMA.CEILING added to the functions that are in our library but not on Microsoft's list (with USDOLLAR), so the counts don't change |
|
||||
| 2026-10-26 | minor | IMSQRT uses Excel's polar route with its cosine reduction, so `IMSQRT("-4")` is `1.22514845490862E-16+2i` as in Excel (exact `2i` before); the rows list the IM* differences still open |
|
||||
| 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?` |
|
||||
|
||||
Reference in New Issue
Block a user