mirror of
https://github.com/nushell/nushell
synced 2025-01-15 14:44:14 +00:00
add % operator for modulus, work with decimals (#2975)
* add % operator, work with decimals * removed the % operator to reserve for something else
This commit is contained in:
parent
388973e9ab
commit
b1e1dab4cb
1 changed files with 20 additions and 0 deletions
|
@ -155,6 +155,12 @@ pub fn compute_values(
|
|||
}
|
||||
Ok(x / bigdecimal::BigDecimal::from(y.clone()))
|
||||
}
|
||||
Operator::Modulo => {
|
||||
if y.is_zero() {
|
||||
return Ok(zero_division_error());
|
||||
}
|
||||
Ok(x % bigdecimal::BigDecimal::from(y.clone()))
|
||||
}
|
||||
_ => Err((left.type_name(), right.type_name())),
|
||||
}?;
|
||||
Ok(UntaggedValue::Primitive(Primitive::Decimal(result)))
|
||||
|
@ -170,6 +176,13 @@ pub fn compute_values(
|
|||
}
|
||||
Ok(bigdecimal::BigDecimal::from(x.clone()) / y)
|
||||
}
|
||||
Operator::Modulo => {
|
||||
if y.is_zero() {
|
||||
return Ok(zero_division_error());
|
||||
}
|
||||
Ok(bigdecimal::BigDecimal::from(x.clone()) % y)
|
||||
}
|
||||
|
||||
_ => Err((left.type_name(), right.type_name())),
|
||||
}?;
|
||||
Ok(UntaggedValue::Primitive(Primitive::Decimal(result)))
|
||||
|
@ -185,6 +198,13 @@ pub fn compute_values(
|
|||
}
|
||||
Ok(x / y)
|
||||
}
|
||||
Operator::Modulo => {
|
||||
if y.is_zero() {
|
||||
return Ok(zero_division_error());
|
||||
}
|
||||
Ok(x % y)
|
||||
}
|
||||
|
||||
_ => Err((left.type_name(), right.type_name())),
|
||||
}?;
|
||||
Ok(UntaggedValue::Primitive(Primitive::Decimal(result)))
|
||||
|
|
Loading…
Reference in a new issue