improve int division to be more nushell-like

This commit is contained in:
JT 2021-09-06 17:35:58 +12:00
parent 76c92fc706
commit a1f7a3c17b

View File

@ -509,10 +509,17 @@ impl Value {
match (self, rhs) { match (self, rhs) {
(Value::Int { val: lhs, .. }, Value::Int { val: rhs, .. }) => { (Value::Int { val: lhs, .. }, Value::Int { val: rhs, .. }) => {
if *rhs != 0 { if *rhs != 0 {
Ok(Value::Int { if lhs % rhs == 0 {
val: lhs / rhs, Ok(Value::Int {
span, val: lhs / rhs,
}) span,
})
} else {
Ok(Value::Float {
val: (*lhs as f64) / (*rhs as f64),
span,
})
}
} else { } else {
Err(ShellError::DivisionByZero(op)) Err(ShellError::DivisionByZero(op))
} }