Migrated numerics to BigInt/BigDecimal

This commit migrates Value's numeric types to BigInt and BigDecimal. The
basic idea is that overflow errors aren't great in a shell environment,
and not really necessary.

The main immediate consequence is that new errors can occur when
serializing Nu values to other formats. You can see this in changes to
the various serialization formats (JSON, TOML, etc.). There's a new
`CoerceInto` trait that uses the `ToPrimitive` trait from `num_traits`
to attempt to coerce a `BigNum` or `BigDecimal` into a target type, and
produces a `RangeError` (kind of `ShellError`) if the coercion fails.

Another possible future consequence is that certain performance-critical
numeric operations might be too slow. If that happens, we can introduce
specialized numeric types to help improve the performance of those
situations, based on the real-world experience.
This commit is contained in:
Yehuda Katz
2019-09-01 09:20:31 -07:00
parent 9e17b937c3
commit 8a29c9e6ab
32 changed files with 525 additions and 340 deletions

View File

@ -12,10 +12,10 @@ impl Sum {
}
fn sum(&mut self, value: Tagged<Value>) -> Result<(), ShellError> {
match value.item {
match value.item() {
Value::Primitive(Primitive::Nothing) => Ok(()),
Value::Primitive(Primitive::Int(i)) => {
match self.total {
match &self.total {
Some(Tagged {
item: Value::Primitive(Primitive::Int(j)),
tag: Tag { span, .. },
@ -26,7 +26,7 @@ impl Sum {
Ok(())
}
None => {
self.total = Some(value);
self.total = Some(value.clone());
Ok(())
}
_ => Err(ShellError::string(format!(