Skip to content

Commit d9c2307

Browse files
committed
Address review comments
* change input parameter of the formatter to usize * add tests
1 parent 7e1cd2f commit d9c2307

1 file changed

Lines changed: 24 additions & 5 deletions

File tree

crates/circuit/src/circuit_drawer.rs

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -684,13 +684,13 @@ struct F64UiFormatter {
684684
}
685685

686686
impl F64UiFormatter {
687-
fn new(num_significant_digits: i32) -> Self {
687+
fn new(num_significant_digits: usize) -> Self {
688688
let options = lexical_write_float::Options::builder()
689-
.max_significant_digits(core::num::NonZeroUsize::new(
690-
num_significant_digits as usize,
689+
.max_significant_digits(core::num::NonZeroUsize::new(num_significant_digits))
690+
.positive_exponent_break(core::num::NonZeroI32::new(num_significant_digits as i32))
691+
.negative_exponent_break(core::num::NonZeroI32::new(
692+
-(num_significant_digits as i32) + 1,
691693
))
692-
.positive_exponent_break(core::num::NonZeroI32::new(num_significant_digits))
693-
.negative_exponent_break(core::num::NonZeroI32::new(-num_significant_digits + 1))
694694
.trim_floats(true)
695695
.build_strict();
696696

@@ -1992,4 +1992,23 @@ q_1: ┤ Rz(1.2346e8) ├┤ Rx(0.12346) ├┤ Rx(1.2346e-5) ├
19921992

19931993
assert_eq!(result, expected.trim_start_matches("\n"));
19941994
}
1995+
1996+
#[test]
1997+
fn test_f64_ui_formatter() {
1998+
let test_data_5_sig_digits = [
1999+
(-1.23, "-1.23"),
2000+
(1.23456, "1.2346"),
2001+
(-12.34567, "-12.346"),
2002+
(123456.78, "123460"),
2003+
(-0.0001, "-0.0001"),
2004+
(12.34 * 1_000_000.0, "1.234e7"),
2005+
(-0.00001, "-1e-5"),
2006+
(12345678.000001, "1.2346e7"),
2007+
];
2008+
2009+
let mut formatter = F64UiFormatter::new(5);
2010+
for test in test_data_5_sig_digits {
2011+
assert_eq!(test.1, formatter.format(test.0));
2012+
}
2013+
}
19952014
}

0 commit comments

Comments
 (0)