diff --git a/crates/engine/src/fill.rs b/crates/engine/src/fill.rs index 63f45431c..b8b71d11f 100644 --- a/crates/engine/src/fill.rs +++ b/crates/engine/src/fill.rs @@ -382,7 +382,7 @@ impl Pattern { /// The exponential curve y = b·m^x fitted to `nums` at positions 0, 1, 2… by least squares on /// the logarithms, as the GROWTH function fits positive numbers. Numbers below zero are fitted /// by their magnitudes and keep their sign. `None` when the numbers are not all above zero or - /// all below zero. A lone number is copied unchanged. + /// all below zero. A lone number, or the same number repeated, is copied unchanged. fn growth(nums: &[f64]) -> Option { let sign = if nums.iter().all(|y| *y > 0.0) { 1.0 @@ -391,7 +391,7 @@ impl Pattern { } else { return None; }; - if nums.len() == 1 { + if nums.windows(2).all(|w| w.first() == w.last()) { return Some(Pattern::Copy); } let logs: Vec = nums.iter().map(|y| (y * sign).ln()).collect(); diff --git a/crates/engine/src/tests.rs b/crates/engine/src/tests.rs index cc98de3ef..e5c236baf 100644 --- a/crates/engine/src/tests.rs +++ b/crates/engine/src/tests.rs @@ -1118,6 +1118,10 @@ fn linear_and_growth_trend_continue_the_fitted_line_or_curve() { s.execute("range.setValues", json!({"range": "Y1", "values": [[big, big14], [big, big14], [big, big14]]})).unwrap(); fill(&mut s, "Y1:Z3", "Y1:Z4", "linearTrend").unwrap(); assert_eq!(nums(&s, &["Y4", "Z4"]), n(&[big, big14])); + // Growth Trend repeats the same number exactly too, huge, tiny or below zero. + s.execute("range.setValues", json!({"range": "AA1", "values": [[1e300, 1e-300, -0.3], [1e300, 1e-300, -0.3]]})).unwrap(); + fill(&mut s, "AA1:AC2", "AA1:AC4", "growthTrend").unwrap(); + assert_eq!(nums(&s, &["AA4", "AB4", "AC4"]), n(&[1e300, 1e-300, -0.3])); s.execute("cell.set", json!({"cell": "N1", "input": "1/15/2026"})).unwrap(); s.execute("cell.set", json!({"cell": "N2", "input": "2/15/2026"})).unwrap(); fill(&mut s, "N1:N2", "N1:N3", "linearTrend").unwrap();