feat: support floats in ordering operators
This commit is contained in:
parent
e4484297a9
commit
872195f6a5
1 changed files with 32 additions and 4 deletions
36
mute-interpreter/src/env/core.rs
vendored
36
mute-interpreter/src/env/core.rs
vendored
|
@ -279,8 +279,15 @@ pub(super) fn core() -> HashMap<String, Node> {
|
|||
Node::NativeFunc(|_env, args| {
|
||||
arg_count!(2, args.len());
|
||||
|
||||
let less_than = match (args[0].borrow(), args[1].borrow()) {
|
||||
let mut args = args.into_iter();
|
||||
let lhs = args.next().unwrap();
|
||||
let rhs = args.next().unwrap();
|
||||
|
||||
let less_than = match (lhs, rhs) {
|
||||
(Node::Int(lhs), Node::Int(rhs)) => lhs < rhs,
|
||||
(Node::Float(lhs), Node::Float(rhs)) => lhs < rhs,
|
||||
(Node::Float(lhs), Node::Int(rhs)) => lhs < rhs as f64,
|
||||
(Node::Int(lhs), Node::Float(rhs)) => (lhs as f64) < rhs,
|
||||
_ => Err(Error::ExpectedNumber)?,
|
||||
};
|
||||
|
||||
|
@ -292,8 +299,15 @@ pub(super) fn core() -> HashMap<String, Node> {
|
|||
Node::NativeFunc(|_env, args| {
|
||||
arg_count!(2, args.len());
|
||||
|
||||
let greater_than = match (args[0].borrow(), args[1].borrow()) {
|
||||
let mut args = args.into_iter();
|
||||
let lhs = args.next().unwrap();
|
||||
let rhs = args.next().unwrap();
|
||||
|
||||
let greater_than = match (lhs, rhs) {
|
||||
(Node::Int(lhs), Node::Int(rhs)) => lhs > rhs,
|
||||
(Node::Float(lhs), Node::Float(rhs)) => lhs > rhs,
|
||||
(Node::Float(lhs), Node::Int(rhs)) => lhs > rhs as f64,
|
||||
(Node::Int(lhs), Node::Float(rhs)) => (lhs as f64) > rhs,
|
||||
_ => Err(Error::ExpectedNumber)?,
|
||||
};
|
||||
|
||||
|
@ -305,8 +319,15 @@ pub(super) fn core() -> HashMap<String, Node> {
|
|||
Node::NativeFunc(|_env, args| {
|
||||
arg_count!(2, args.len());
|
||||
|
||||
let less_than_equal = match (args[0].borrow(), args[1].borrow()) {
|
||||
let mut args = args.into_iter();
|
||||
let lhs = args.next().unwrap();
|
||||
let rhs = args.next().unwrap();
|
||||
|
||||
let less_than_equal = match (lhs, rhs) {
|
||||
(Node::Int(lhs), Node::Int(rhs)) => lhs <= rhs,
|
||||
(Node::Float(lhs), Node::Float(rhs)) => lhs <= rhs,
|
||||
(Node::Float(lhs), Node::Int(rhs)) => lhs <= rhs as f64,
|
||||
(Node::Int(lhs), Node::Float(rhs)) => (lhs as f64) <= rhs,
|
||||
_ => Err(Error::ExpectedNumber)?,
|
||||
};
|
||||
|
||||
|
@ -318,8 +339,15 @@ pub(super) fn core() -> HashMap<String, Node> {
|
|||
Node::NativeFunc(|_env, args| {
|
||||
arg_count!(2, args.len());
|
||||
|
||||
let greater_than_equal = match (args[0].borrow(), args[1].borrow()) {
|
||||
let mut args = args.into_iter();
|
||||
let lhs = args.next().unwrap();
|
||||
let rhs = args.next().unwrap();
|
||||
|
||||
let greater_than_equal = match (lhs, rhs) {
|
||||
(Node::Int(lhs), Node::Int(rhs)) => lhs >= rhs,
|
||||
(Node::Float(lhs), Node::Float(rhs)) => lhs >= rhs,
|
||||
(Node::Float(lhs), Node::Int(rhs)) => lhs >= rhs as f64,
|
||||
(Node::Int(lhs), Node::Float(rhs)) => (lhs as f64) >= rhs,
|
||||
_ => Err(Error::ExpectedNumber)?,
|
||||
};
|
||||
|
||||
|
|
Loading…
Reference in a new issue