bigdecimal-rs icon indicating copy to clipboard operation
bigdecimal-rs copied to clipboard

Support representation of infinity

Open thegedge opened this issue 5 years ago • 1 comments

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?

thegedge avatar Aug 24 '20 19:08 thegedge

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! 🙂

thegedge avatar Aug 24 '20 23:08 thegedge