diff --git a/crates/engine/src/fill.rs b/crates/engine/src/fill.rs index c4354ec7c..1201721da 100644 --- a/crates/engine/src/fill.rs +++ b/crates/engine/src/fill.rs @@ -593,7 +593,7 @@ pub fn series(cx: &mut Ctx, sheet: usize, options: SeriesOptions<'_>) -> Result< }; // The stop value bounds the series in the direction it runs (a growth by 0.5 falls). if let Some(s) = stop - && ((v >= prev && v > s) || (v < prev && v < s)) + && ((v >= prev && round15(v) > s) || (v < prev && round15(v) < s)) { break; } @@ -806,6 +806,21 @@ mod tests { assert_eq!(sh.value(CellRef::new(1, 1)), Value::from("03/12/2023")); } + #[test] + fn series_keeps_value_equal_to_stop_after_float_drift() { + let mut s = crate::Session::new(); + s.new_workbook(); + s.execute("cell.set", serde_json::json!({"cell": "A1", "input": "1"})).unwrap(); + s.execute("edit.fillSeries", serde_json::json!({"range": "A1:A6", "type": "linear", "step": 0.1, "stop": 1.3})).unwrap(); + s.execute("cell.set", serde_json::json!({"cell": "B1", "input": "0.1"})).unwrap(); + s.execute("edit.fillSeries", serde_json::json!({"range": "B1:B4", "type": "growth", "step": 3, "stop": 0.3})).unwrap(); + let sh = s.doc().unwrap().wb.active().unwrap(); + let col = |c: u32, n: u32| (0..n).map(|r| sh.value(CellRef::new(r, c))).collect::>(); + let n = Value::number; + assert_eq!(col(0, 6), vec![n(1.0), n(1.1), n(1.2), n(1.3), Value::Empty, Value::Empty]); + assert_eq!(col(1, 4), vec![n(0.1), n(0.3), Value::Empty, Value::Empty]); + } + #[test] fn flash_programs() { let p = learn(&[("John Smith".into(), "Smith, John".into())]).unwrap();