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:
Michael Schimmel
2026-02-22 08:49:14 +01:00
parent 589c13896f
commit df06c51205
2 changed files with 80 additions and 0 deletions
+14
View File
@@ -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,