rust-num / num-complex

Complex numbers for Rust
Apache License 2.0
232 stars 49 forks source link

Changing display format to a more compact form. #96

Closed ErikBuer closed 2 years ago

ErikBuer commented 3 years ago

Hi, I am new to Rust, and open source contribution, so please bear with me..

When debugging arrays of complex numbers i find the formatting to be unnecessarily long, making it hard to see what is going on in the data. See the example below.

I therefore propose to change the debug and display formatting to a+bi, e.g. 1+2i.

Note that in the example below, Github doesn't wrap the line.

stderr:
thread 'main' panicked at 'assertion failed: `(left == right)`
  left: `[Complex { re: 1, im: 0 }, Complex { re: 1, im: 0 }, Complex { re: 1, im: 0 }, Complex { re: 1, im: 0 }, Complex { re: 1, im: 0 }, Complex { re: 1, im: 0 }, Complex { re: 1, im: 0 }, Complex { re: 1, im: 0 }, Complex { re: 1, im: 0 }, Complex { re: 1, im: 0 }, Complex { re: 1, im: 0 }, Complex { re: 1, im: 0 }, Complex { re: 1, im: 0 }, Complex { re: 1, im: 0 }, Complex { re: 1, im: 0 }, Complex { re: 1, im: 0 }]`,
 right: `[Complex { re: 0, im: 0 }, Complex { re: 0, im: 0 }, Complex { re: 0, im: 0 }, Complex { re: 0, im: 0 }, Complex { re: 0, im: 0 }, Complex { re: 0, im: 0 }, Complex { re: 0, im: 0 }, Complex { re: 0, im: 0 }, Complex { re: 0, im: 0 }, Complex { re: 0, im: 0 }, Complex { re: 0, im: 0 }, Complex { re: 0, im: 0 }, Complex { re: 0, im: 0 }, Complex { re: 0, im: 0 }, Complex { re: 0, im: 0 }, Complex { re: 0, im: 0 }]`', src/lib.rs:13:1
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

Erik.

cuviper commented 2 years ago

Display should already have that compact form, but there's a reasonable case to be made for Debug as well. We did make that change for BigInt and BigUint in rust-num/num-bigint#195, but it's somewhat debatable whether that should be considered a breaking change. In that case, I was getting ready for a semver bump anyway.

ErikBuer commented 2 years ago

Yes, I see now. I appreciate the feedback!

Erik.