Add math and random functions
Register `abs`, `min`, `max`, and `random` functions to the environment. This also includes adding `PartialOrd` implementation for `Value` to support comparisons for `min` and `max`.
This commit is contained in:
@@ -117,6 +117,20 @@ impl PartialEq for Value {
|
||||
}
|
||||
}
|
||||
|
||||
impl PartialOrd for Value {
|
||||
fn partial_cmp(&self, other: &Self) -> Option<std::cmp::Ordering> {
|
||||
match (self, other) {
|
||||
(Value::Int(a), Value::Int(b)) => a.partial_cmp(b),
|
||||
(Value::Float(a), Value::Float(b)) => a.partial_cmp(b),
|
||||
(Value::Int(a), Value::Float(b)) => (*a as f64).partial_cmp(b),
|
||||
(Value::Float(a), Value::Int(b)) => a.partial_cmp(&(*b as f64)),
|
||||
(Value::DateTime(a), Value::DateTime(b)) => a.partial_cmp(b),
|
||||
(Value::Text(a), Value::Text(b)) => a.partial_cmp(b),
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
||||
pub struct Signature {
|
||||
pub params: StaticType,
|
||||
|
||||
Reference in New Issue
Block a user