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:
Darren Schroeder 2021-01-26 12:42:34 -06:00 committed by GitHub
parent 388973e9ab
commit b1e1dab4cb
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -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)))