mirror of
https://github.com/nushell/nushell
synced 2024-11-10 23:24:14 +00:00
improve int division to be more nushell-like
This commit is contained in:
parent
76c92fc706
commit
a1f7a3c17b
1 changed files with 11 additions and 4 deletions
|
@ -509,10 +509,17 @@ impl Value {
|
|||
match (self, rhs) {
|
||||
(Value::Int { val: lhs, .. }, Value::Int { val: rhs, .. }) => {
|
||||
if *rhs != 0 {
|
||||
Ok(Value::Int {
|
||||
val: lhs / rhs,
|
||||
span,
|
||||
})
|
||||
if lhs % rhs == 0 {
|
||||
Ok(Value::Int {
|
||||
val: lhs / rhs,
|
||||
span,
|
||||
})
|
||||
} else {
|
||||
Ok(Value::Float {
|
||||
val: (*lhs as f64) / (*rhs as f64),
|
||||
span,
|
||||
})
|
||||
}
|
||||
} else {
|
||||
Err(ShellError::DivisionByZero(op))
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue