bigdecimal-rs
bigdecimal-rs copied to clipboard
Support representation of infinity
fn main() {
println!("{:?}", str::parse::<f64>("inf"));
println!("{:?}", str::parse::<f64>("+inf"));
println!("{:?}", str::parse::<f64>("-inf"));
println!("{:?}", str::parse::<f64>("inf").map(|v| v * 10.0));
println!("{:?}", str::parse::<f64>("inf").map(|v| v * -10.0));
println!("{:?}", str::parse::<f64>("inf").map(|v| v * 0.0));
}
Outputs
Ok(inf)
Ok(inf)
Ok(-inf)
Ok(inf)
Ok(-inf)
Ok(NaN)
This representation in f64 but not in BigDecimal resulted in a few issues being opened on nushell/nushell.
We were wondering if bigdecimal would be open to supporting the representation of Infinity and NaN?
https://github.com/akubera/bigdecimal-rs/pull/65 is a step in the right direction, giving us a way to at least avoid a panic. I still think it's possible to support these representations, but if this crate would prefer sticking with finite values, https://github.com/akubera/bigdecimal-rs/pull/65 works for us! 🙂