isaacholt100 / bnum

Arbitrary, fixed size numeric types that extend the functionality of primitive numeric types in Rust.
https://crates.io/crates/bnum
Other
73 stars 10 forks source link

Display impl acts differently from `std`'s #25

Closed chipshort closed 1 year ago

chipshort commented 1 year ago

Not sure if this counts as a bug, but since your proclaimed goal is to act like std's integer types: The Display impl does not pad numbers. This test fails:

#[test]
fn display_pad() {
    use bnum::prelude::*;
    let std = 1u128;
    let bnum: bnum::types::U128 = std.as_();

    assert_eq!(format!("{:05}", std), format!("{:05}", bnum));
}
panicked at 'assertion failed: `(left == right)`
  left: `"00001"`,
 right: `"1"`'

I haven't checked any of the other formatting options, but those might be worth looking at too.

isaacholt100 commented 1 year ago

Hi @chipshort, thanks very much for opening this issue! Funnily enough, I had just realised a few days ago that I hadn't properly implemented Display properly for uints. I believe that Display was correctly implemented for signed ints, but for some reason I forgot to use Formatter::pad_integral in the implementation for uints. I've added a fix to this which should be consistent with std integer formatting, which will be added when I publish the next version.

isaacholt100 commented 1 year ago

I've just published v0.8.0 which fixes this, so closing this issue.