mirror of
https://github.com/nushell/nushell.git
synced 2024-12-16 20:21:09 +01:00
Merge pull request #22 from jntrnr/div_int
improve int division to be more nushell-like
This commit is contained in:
commit
cdbd333c9b
@ -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 New Issue
Block a user