Skip to content

Creating small decimal sometimes gives NaN #117

@Danvil

Description

@Danvil

Creating a small decimal when using u32 as type data sometimes gives NaN instead of 0.

Code:

pub type Dec = fraction::GenericDecimal<u32, u8>;
let d = Dec::from(0.0000000001);
println!("{d:?}");

Output:

GenericDecimal(NaN | prec=0; NaN; NaN)

Testing a bit more:

  • Dec::from(0.000000001) => GenericDecimal(0.000000001 | prec=9; Rational(Plus, Ratio { numer: 1, denom: 1000000000 }); 0.000000001)
  • Dec::from(0.0000000001); => GenericDecimal(NaN | prec=0; NaN; NaN)
  • ...
  • Dec::from(0.000000000000001); => GenericDecimal(NaN | prec=0; NaN; NaN)
  • Dec::from(0.0000000000000001); => GenericDecimal(0 | prec=0; Rational(Plus, Ratio { numer: 0, denom: 1 }); 0)

Version: "0.15.3"

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions