feat: add floats
This commit is contained in:
@@ -94,6 +94,7 @@ fn evaluate_unary(op: UnaryOp, val: &ConstantValue) -> Option<ConstantValue> {
|
||||
(UnaryOp::Neg, ConstantValue::Integer(v, ty)) => {
|
||||
Some(ConstantValue::Integer(v.wrapping_neg(), ty.clone()))
|
||||
}
|
||||
(UnaryOp::Neg, ConstantValue::Float(v, ty)) => Some(ConstantValue::Float(-v, ty.clone())),
|
||||
(UnaryOp::Not, ConstantValue::Boolean(b)) => Some(ConstantValue::Boolean(!b)),
|
||||
_ => None,
|
||||
}
|
||||
@@ -165,6 +166,20 @@ fn evaluate_binary(
|
||||
_ => None,
|
||||
},
|
||||
|
||||
(ConstantValue::Float(l, ty), ConstantValue::Float(r, _)) => match op {
|
||||
BinaryOp::Add => Some(ConstantValue::Float(l + r, ty.clone())),
|
||||
BinaryOp::Sub => Some(ConstantValue::Float(l - r, ty.clone())),
|
||||
BinaryOp::Mul => Some(ConstantValue::Float(l * r, ty.clone())),
|
||||
BinaryOp::Div => Some(ConstantValue::Float(l / r, ty.clone())),
|
||||
BinaryOp::Rem => Some(ConstantValue::Float(l % r, ty.clone())),
|
||||
BinaryOp::Eq => Some(ConstantValue::Boolean(l == r)),
|
||||
BinaryOp::Neq => Some(ConstantValue::Boolean(l != r)),
|
||||
BinaryOp::Lt => Some(ConstantValue::Boolean(l < r)),
|
||||
BinaryOp::Le => Some(ConstantValue::Boolean(l <= r)),
|
||||
BinaryOp::Gt => Some(ConstantValue::Boolean(l > r)),
|
||||
BinaryOp::Ge => Some(ConstantValue::Boolean(l >= r)),
|
||||
},
|
||||
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user