Fix: Improve series type handling and coercions
This commit enhances the series type handling in `src/ast/rtl/series.rs` by introducing helper methods `as_float` and `as_int` in `src/ast/types.rs` to manage type conversions more robustly. It also updates the function overload resolution in `src/ast/types.rs` to prioritize exact parameter matches before falling back to implicit coercions. Finally, the example `err.myc` has been updated to reflect a more accurate implementation of a Simple Moving Average (SMA) calculation.
This commit is contained in:
@@ -218,19 +218,16 @@ pub trait SeriesMember: Object + Series {
|
||||
|
||||
impl SeriesMember for ScalarSeries<f64> {
|
||||
fn push_value(&self, value: Value, limit: Option<usize>) {
|
||||
match value {
|
||||
Value::Float(v) => self.data.borrow_mut().push(v, limit),
|
||||
Value::Int(v) => self.data.borrow_mut().push(v as f64, limit),
|
||||
_ => {}
|
||||
if let Some(v) = value.as_float() {
|
||||
self.data.borrow_mut().push(v, limit);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl SeriesMember for ScalarSeries<i64> {
|
||||
fn push_value(&self, value: Value, limit: Option<usize>) {
|
||||
match value {
|
||||
Value::Int(v) | Value::DateTime(v) => self.data.borrow_mut().push(v, limit),
|
||||
_ => {}
|
||||
if let Some(v) = value.as_int() {
|
||||
self.data.borrow_mut().push(v, limit);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user