Skip to content

Commit 2784b89

Browse files
committed
Remove support for zero padding
1 parent e044cfb commit 2784b89

File tree

1 file changed

+4
-17
lines changed

1 file changed

+4
-17
lines changed

complex/src/lib.rs

Lines changed: 4 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -621,8 +621,8 @@ macro_rules! write_complex {
621621
let abs_re = if $re < Zero::zero() { $T::zero() - $re.clone() } else { $re.clone() };
622622
let abs_im = if $im < Zero::zero() { $T::zero() - $im.clone() } else { $im.clone() };
623623

624-
let mut real: String;
625-
let mut imag: String;
624+
let real: String;
625+
let imag: String;
626626

627627
if let Some(prec) = $f.precision() {
628628
real = format!(concat!("{:.1$", $t, "}"), abs_re, prec);
@@ -642,18 +642,6 @@ macro_rules! write_complex {
642642
""
643643
};
644644

645-
if $f.sign_aware_zero_pad() && $f.width().is_some() {
646-
let total_width = $f.width().unwrap();
647-
// Subtract leading sign, two prefixes, middle operator and trailing 'i'
648-
// to obtain the width scalars need to be padded to
649-
let subtract = sign.len() + prefix.len()*2 + 1 + 1;
650-
let scalar_width = total_width - subtract;
651-
let real_width = scalar_width - (scalar_width/2);
652-
let imag_width = scalar_width/2;
653-
real = format!("{0:0>1$}", real, real_width);
654-
imag = format!("{0:0>1$}", imag, imag_width);
655-
}
656-
657645
let complex = if $im < Zero::zero() {
658646
format!("{}{pre}{re}-{pre}{im}i", sign, re=real, im=imag, pre=prefix)
659647
}
@@ -1314,18 +1302,17 @@ mod test {
13141302
assert_eq!(format!("{}", a), "1.23456+123.456i");
13151303
assert_eq!(format!("{:.2}", a), "1.23+123.46i");
13161304
assert_eq!(format!("{:.2e}", a), "1.23e0+1.23e2i");
1317-
assert_eq!(format!("{:+020.2E}", a), "+0001.23E0+001.23E2i");
1305+
assert_eq!(format!("{:+20.2E}", a), " +1.23E0+1.23E2i");
13181306

13191307
let b = Complex::new(0x80, 0xff);
13201308
assert_eq!(format!("{:X}", b), "80+FFi");
13211309
assert_eq!(format!("{:#x}", b), "0x80+0xffi");
13221310
assert_eq!(format!("{:+#b}", b), "+0b10000000+0b11111111i");
13231311
assert_eq!(format!("{:+#16o}", b), " +0o200+0o377i");
1324-
assert_eq!(format!("{:+#016x}", b), "+0x00080+0x00ffi");
13251312

13261313
let c = Complex::new(-10, -10000);
13271314
assert_eq!(format!("{}", c), "-10-10000i");
1328-
assert_eq!(format!("{:016}", c), "-0000010-010000i");
1315+
assert_eq!(format!("{:16}", c), " -10-10000i");
13291316
}
13301317

13311318
#[test]

0 commit comments

Comments
 (0)