Skip to content

Commit

Permalink
fix rounding issue with exponents in fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
mj10021 committed Nov 11, 2023
1 parent ed086d8 commit e81964e
Show file tree
Hide file tree
Showing 2 changed files with 357 additions and 4 deletions.
8 changes: 8 additions & 0 deletions library/core/src/fmt/num.rs
Original file line number Diff line number Diff line change
Expand Up @@ -334,8 +334,16 @@ macro_rules! impl_Exp {
// round up last digit
if rem >= 5 {
n += 1;
// if the digit is rounded to the next power
// instead adjust the exponent
if n % 10 == 0 {
n /= 10;
exponent += 1;
}
}
// n = 100
}
// assert!(n == 666, "{}\n{}\n{}\n",n, exponent, added_precision);
(n, exponent, exponent, added_precision)
};

Expand Down
353 changes: 349 additions & 4 deletions library/core/tests/fmt/num.rs
Original file line number Diff line number Diff line change
Expand Up @@ -128,30 +128,375 @@ fn test_format_int_exp_precision() {
let big_int: u32 = 314_159_265;
assert_eq!(format!("{big_int:.1e}"), format!("{:.1e}", f64::from(big_int)));

//test adding precision
// test adding precision
assert_eq!(format!("{:.10e}", i8::MIN), "-1.2800000000e2");
assert_eq!(format!("{:.10e}", i16::MIN), "-3.2768000000e4");
assert_eq!(format!("{:.10e}", i32::MIN), "-2.1474836480e9");
assert_eq!(format!("{:.20e}", i64::MIN), "-9.22337203685477580800e18");
assert_eq!(format!("{:.40e}", i128::MIN), "-1.7014118346046923173168730371588410572800e38");

//test rounding
// test rounding
assert_eq!(format!("{:.1e}", i8::MIN), "-1.3e2");
assert_eq!(format!("{:.1e}", i16::MIN), "-3.3e4");
assert_eq!(format!("{:.1e}", i32::MIN), "-2.1e9");
assert_eq!(format!("{:.1e}", i64::MIN), "-9.2e18");
assert_eq!(format!("{:.1e}", i128::MIN), "-1.7e38");

//test huge precision
// test huge precision
assert_eq!(format!("{:.1000e}", 1), format!("1.{}e0", "0".repeat(1000)));
//test zero precision
assert_eq!(format!("{:.0e}", 1), format!("1e0",));
assert_eq!(format!("{:.0e}", 35), format!("4e1",));

//test padding with precision (and sign)
// test padding with precision (and sign)
assert_eq!(format!("{:+10.3e}", 1), " +1.000e0");
}

#[test]
fn new_test() {
// test precision remains correct when rounding to next power
assert_eq!(format!("{:.1e}", 999), "1.0e3");
assert_eq!(format!("{:.1e}", 1001), "1.0e3");
assert_eq!(format!("{:.1e}", 1000), "1.0e3");
assert_eq!(format!("{:.0e}", -999), "-1e3");
assert_eq!(format!("{:.0e}", -998), "-1e3");
assert_eq!(format!("{:.0e}", -997), "-1e3");
assert_eq!(format!("{:.0e}", -996), "-1e3");
assert_eq!(format!("{:.0e}", -995), "-1e3");
assert_eq!(format!("{:.0e}", -994), "-1e3");
assert_eq!(format!("{:.0e}", -993), "-1e3");
assert_eq!(format!("{:.0e}", -992), "-1e3");
assert_eq!(format!("{:.0e}", -991), "-1e3");
assert_eq!(format!("{:.0e}", -990), "-1e3");
assert_eq!(format!("{:.0e}", -989), "-1e3");
assert_eq!(format!("{:.0e}", -988), "-1e3");
assert_eq!(format!("{:.0e}", -987), "-1e3");
assert_eq!(format!("{:.0e}", -986), "-1e3");
assert_eq!(format!("{:.0e}", -985), "-1e3");
assert_eq!(format!("{:.0e}", -984), "-1e3");
assert_eq!(format!("{:.0e}", -983), "-1e3");
assert_eq!(format!("{:.0e}", -982), "-1e3");
assert_eq!(format!("{:.0e}", -981), "-1e3");
assert_eq!(format!("{:.0e}", -980), "-1e3");
assert_eq!(format!("{:.0e}", -979), "-1e3");
assert_eq!(format!("{:.0e}", -978), "-1e3");
assert_eq!(format!("{:.0e}", -977), "-1e3");
assert_eq!(format!("{:.0e}", -976), "-1e3");
assert_eq!(format!("{:.0e}", -975), "-1e3");
assert_eq!(format!("{:.0e}", -974), "-1e3");
assert_eq!(format!("{:.0e}", -973), "-1e3");
assert_eq!(format!("{:.0e}", -972), "-1e3");
assert_eq!(format!("{:.0e}", -971), "-1e3");
assert_eq!(format!("{:.0e}", -970), "-1e3");
assert_eq!(format!("{:.0e}", -969), "-1e3");
assert_eq!(format!("{:.0e}", -968), "-1e3");
assert_eq!(format!("{:.0e}", -967), "-1e3");
assert_eq!(format!("{:.0e}", -966), "-1e3");
assert_eq!(format!("{:.0e}", -965), "-1e3");
assert_eq!(format!("{:.0e}", -964), "-1e3");
assert_eq!(format!("{:.0e}", -963), "-1e3");
assert_eq!(format!("{:.0e}", -962), "-1e3");
assert_eq!(format!("{:.0e}", -961), "-1e3");
assert_eq!(format!("{:.0e}", -960), "-1e3");
assert_eq!(format!("{:.0e}", -959), "-1e3");
assert_eq!(format!("{:.0e}", -958), "-1e3");
assert_eq!(format!("{:.0e}", -957), "-1e3");
assert_eq!(format!("{:.0e}", -956), "-1e3");
assert_eq!(format!("{:.0e}", -955), "-1e3");
assert_eq!(format!("{:.0e}", -954), "-1e3");
assert_eq!(format!("{:.0e}", -953), "-1e3");
assert_eq!(format!("{:.0e}", -952), "-1e3");
assert_eq!(format!("{:.0e}", -951), "-1e3");
assert_eq!(format!("{:.0e}", -950), "-1e3");
assert_eq!(format!("{:.0e}", -850), "-9e2");
assert_eq!(format!("{:.0e}", -650), "-7e2");
assert_eq!(format!("{:.0e}", -450), "-5e2");
assert_eq!(format!("{:.0e}", -250), "-3e2");
assert_eq!(format!("{:.0e}", -99), "-1e2");
assert_eq!(format!("{:.0e}", -98), "-1e2");
assert_eq!(format!("{:.0e}", -97), "-1e2");
assert_eq!(format!("{:.0e}", -96), "-1e2");
assert_eq!(format!("{:.0e}", -95), "-1e2");
assert_eq!(format!("{:.0e}", -85), "-9e1");
assert_eq!(format!("{:.0e}", -65), "-7e1");
assert_eq!(format!("{:.0e}", -45), "-5e1");
assert_eq!(format!("{:.0e}", -25), "-3e1");
assert_eq!(format!("{:.0e}", 25), "3e1");
assert_eq!(format!("{:.0e}", 45), "5e1");
assert_eq!(format!("{:.0e}", 65), "7e1");
assert_eq!(format!("{:.0e}", 85), "9e1");
assert_eq!(format!("{:.0e}", 94), "9e1");
assert_eq!(format!("{:.0e}", 95), "1e2");
assert_eq!(format!("{:.0e}", 96), "1e2");
assert_eq!(format!("{:.0e}", 97), "1e2");
assert_eq!(format!("{:.0e}", 98), "1e2");
assert_eq!(format!("{:.0e}", 99), "1e2");
assert_eq!(format!("{:.0e}", 250), "3e2");
assert_eq!(format!("{:.0e}", 450), "5e2");
assert_eq!(format!("{:.0e}", 650), "7e2");
assert_eq!(format!("{:.0e}", 850), "9e2");
assert_eq!(format!("{:.0e}", 950), "1e3");
assert_eq!(format!("{:.0e}", 951), "1e3");
assert_eq!(format!("{:.0e}", 952), "1e3");
assert_eq!(format!("{:.0e}", 953), "1e3");
assert_eq!(format!("{:.0e}", 954), "1e3");
assert_eq!(format!("{:.0e}", 955), "1e3");
assert_eq!(format!("{:.0e}", 956), "1e3");
assert_eq!(format!("{:.0e}", 957), "1e3");
assert_eq!(format!("{:.0e}", 958), "1e3");
assert_eq!(format!("{:.0e}", 959), "1e3");
assert_eq!(format!("{:.0e}", 960), "1e3");
assert_eq!(format!("{:.0e}", 961), "1e3");
assert_eq!(format!("{:.0e}", 962), "1e3");
assert_eq!(format!("{:.0e}", 963), "1e3");
assert_eq!(format!("{:.0e}", 964), "1e3");
assert_eq!(format!("{:.0e}", 965), "1e3");
assert_eq!(format!("{:.0e}", 966), "1e3");
assert_eq!(format!("{:.0e}", 967), "1e3");
assert_eq!(format!("{:.0e}", 968), "1e3");
assert_eq!(format!("{:.0e}", 969), "1e3");
assert_eq!(format!("{:.0e}", 970), "1e3");
assert_eq!(format!("{:.0e}", 971), "1e3");
assert_eq!(format!("{:.0e}", 972), "1e3");
assert_eq!(format!("{:.0e}", 973), "1e3");
assert_eq!(format!("{:.0e}", 974), "1e3");
assert_eq!(format!("{:.0e}", 975), "1e3");
assert_eq!(format!("{:.0e}", 976), "1e3");
assert_eq!(format!("{:.0e}", 977), "1e3");
assert_eq!(format!("{:.0e}", 978), "1e3");
assert_eq!(format!("{:.0e}", 979), "1e3");
assert_eq!(format!("{:.0e}", 980), "1e3");
assert_eq!(format!("{:.0e}", 981), "1e3");
assert_eq!(format!("{:.0e}", 982), "1e3");
assert_eq!(format!("{:.0e}", 983), "1e3");
assert_eq!(format!("{:.0e}", 984), "1e3");
assert_eq!(format!("{:.0e}", 985), "1e3");
assert_eq!(format!("{:.0e}", 986), "1e3");
assert_eq!(format!("{:.0e}", 987), "1e3");
assert_eq!(format!("{:.0e}", 988), "1e3");
assert_eq!(format!("{:.0e}", 989), "1e3");
assert_eq!(format!("{:.0e}", 990), "1e3");
assert_eq!(format!("{:.0e}", 991), "1e3");
assert_eq!(format!("{:.0e}", 992), "1e3");
assert_eq!(format!("{:.0e}", 993), "1e3");
assert_eq!(format!("{:.0e}", 994), "1e3");
assert_eq!(format!("{:.0e}", 995), "1e3");
assert_eq!(format!("{:.0e}", 996), "1e3");
assert_eq!(format!("{:.0e}", 997), "1e3");
assert_eq!(format!("{:.0e}", 998), "1e3");
assert_eq!(format!("{:.0e}", 999), "1e3");
assert_eq!(format!("{:.1e}", -1850), "-1.9e3");
assert_eq!(format!("{:.1e}", -1650), "-1.7e3");
assert_eq!(format!("{:.1e}", -1450), "-1.5e3");
assert_eq!(format!("{:.1e}", -1250), "-1.3e3");
assert_eq!(format!("{:.1e}", -1050), "-1.1e3");
assert_eq!(format!("{:.1e}", -999), "-1.0e3");
assert_eq!(format!("{:.1e}", -998), "-1.0e3");
assert_eq!(format!("{:.1e}", -997), "-1.0e3");
assert_eq!(format!("{:.1e}", -996), "-1.0e3");
assert_eq!(format!("{:.1e}", -995), "-1.0e3");
assert_eq!(format!("{:.1e}", -985), "-9.9e2");
assert_eq!(format!("{:.1e}", -965), "-9.7e2");
assert_eq!(format!("{:.1e}", -945), "-9.5e2");
assert_eq!(format!("{:.1e}", -925), "-9.3e2");
assert_eq!(format!("{:.1e}", -905), "-9.1e2");
assert_eq!(format!("{:.1e}", -885), "-8.9e2");
assert_eq!(format!("{:.1e}", -865), "-8.7e2");
assert_eq!(format!("{:.1e}", -845), "-8.5e2");
assert_eq!(format!("{:.1e}", -825), "-8.3e2");
assert_eq!(format!("{:.1e}", -805), "-8.1e2");
assert_eq!(format!("{:.1e}", -785), "-7.9e2");
assert_eq!(format!("{:.1e}", -765), "-7.7e2");
assert_eq!(format!("{:.1e}", -745), "-7.5e2");
assert_eq!(format!("{:.1e}", -725), "-7.3e2");
assert_eq!(format!("{:.1e}", -705), "-7.1e2");
assert_eq!(format!("{:.1e}", -685), "-6.9e2");
assert_eq!(format!("{:.1e}", -665), "-6.7e2");
assert_eq!(format!("{:.1e}", -645), "-6.5e2");
assert_eq!(format!("{:.1e}", -625), "-6.3e2");
assert_eq!(format!("{:.1e}", -605), "-6.1e2");
assert_eq!(format!("{:.1e}", -585), "-5.9e2");
assert_eq!(format!("{:.1e}", -565), "-5.7e2");
assert_eq!(format!("{:.1e}", -545), "-5.5e2");
assert_eq!(format!("{:.1e}", -525), "-5.3e2");
assert_eq!(format!("{:.1e}", -505), "-5.1e2");
assert_eq!(format!("{:.1e}", -485), "-4.9e2");
assert_eq!(format!("{:.1e}", -465), "-4.7e2");
assert_eq!(format!("{:.1e}", -445), "-4.5e2");
assert_eq!(format!("{:.1e}", -425), "-4.3e2");
assert_eq!(format!("{:.1e}", -405), "-4.1e2");
assert_eq!(format!("{:.1e}", -385), "-3.9e2");
assert_eq!(format!("{:.1e}", -365), "-3.7e2");
assert_eq!(format!("{:.1e}", -345), "-3.5e2");
assert_eq!(format!("{:.1e}", -325), "-3.3e2");
assert_eq!(format!("{:.1e}", -305), "-3.1e2");
assert_eq!(format!("{:.1e}", -285), "-2.9e2");
assert_eq!(format!("{:.1e}", -265), "-2.7e2");
assert_eq!(format!("{:.1e}", -245), "-2.5e2");
assert_eq!(format!("{:.1e}", -225), "-2.3e2");
assert_eq!(format!("{:.1e}", -205), "-2.1e2");
assert_eq!(format!("{:.1e}", -185), "-1.9e2");
assert_eq!(format!("{:.1e}", -165), "-1.7e2");
assert_eq!(format!("{:.1e}", -145), "-1.5e2");
assert_eq!(format!("{:.1e}", -125), "-1.3e2");
assert_eq!(format!("{:.1e}", -105), "-1.1e2");
assert_eq!(format!("{:.1e}", 105), "1.1e2");
assert_eq!(format!("{:.1e}", 125), "1.3e2");
assert_eq!(format!("{:.1e}", 145), "1.5e2");
assert_eq!(format!("{:.1e}", 165), "1.7e2");
assert_eq!(format!("{:.1e}", 185), "1.9e2");
assert_eq!(format!("{:.1e}", 205), "2.1e2");
assert_eq!(format!("{:.1e}", 225), "2.3e2");
assert_eq!(format!("{:.1e}", 245), "2.5e2");
assert_eq!(format!("{:.1e}", 265), "2.7e2");
assert_eq!(format!("{:.1e}", 285), "2.9e2");
assert_eq!(format!("{:.1e}", 305), "3.1e2");
assert_eq!(format!("{:.1e}", 325), "3.3e2");
assert_eq!(format!("{:.1e}", 345), "3.5e2");
assert_eq!(format!("{:.1e}", 365), "3.7e2");
assert_eq!(format!("{:.1e}", 385), "3.9e2");
assert_eq!(format!("{:.1e}", 405), "4.1e2");
assert_eq!(format!("{:.1e}", 425), "4.3e2");
assert_eq!(format!("{:.1e}", 445), "4.5e2");
assert_eq!(format!("{:.1e}", 465), "4.7e2");
assert_eq!(format!("{:.1e}", 485), "4.9e2");
assert_eq!(format!("{:.1e}", 505), "5.1e2");
assert_eq!(format!("{:.1e}", 525), "5.3e2");
assert_eq!(format!("{:.1e}", 545), "5.5e2");
assert_eq!(format!("{:.1e}", 565), "5.7e2");
assert_eq!(format!("{:.1e}", 585), "5.9e2");
assert_eq!(format!("{:.1e}", 605), "6.1e2");
assert_eq!(format!("{:.1e}", 625), "6.3e2");
assert_eq!(format!("{:.1e}", 645), "6.5e2");
assert_eq!(format!("{:.1e}", 665), "6.7e2");
assert_eq!(format!("{:.1e}", 685), "6.9e2");
assert_eq!(format!("{:.1e}", 705), "7.1e2");
assert_eq!(format!("{:.1e}", 725), "7.3e2");
assert_eq!(format!("{:.1e}", 745), "7.5e2");
assert_eq!(format!("{:.1e}", 765), "7.7e2");
assert_eq!(format!("{:.1e}", 785), "7.9e2");
assert_eq!(format!("{:.1e}", 805), "8.1e2");
assert_eq!(format!("{:.1e}", 825), "8.3e2");
assert_eq!(format!("{:.1e}", 845), "8.5e2");
assert_eq!(format!("{:.1e}", 865), "8.7e2");
assert_eq!(format!("{:.1e}", 885), "8.9e2");
assert_eq!(format!("{:.1e}", 905), "9.1e2");
assert_eq!(format!("{:.1e}", 925), "9.3e2");
assert_eq!(format!("{:.1e}", 945), "9.5e2");
assert_eq!(format!("{:.1e}", 965), "9.7e2");
assert_eq!(format!("{:.1e}", 985), "9.9e2");
assert_eq!(format!("{:.1e}", 995), "1.0e3");
assert_eq!(format!("{:.1e}", 996), "1.0e3");
assert_eq!(format!("{:.1e}", 997), "1.0e3");
assert_eq!(format!("{:.1e}", 998), "1.0e3");
assert_eq!(format!("{:.1e}", 999), "1.0e3");
assert_eq!(format!("{:.1e}", 1050), "1.1e3");
assert_eq!(format!("{:.1e}", 1250), "1.3e3");
assert_eq!(format!("{:.1e}", 1450), "1.5e3");
assert_eq!(format!("{:.1e}", 1650), "1.7e3");
assert_eq!(format!("{:.1e}", 1850), "1.9e3");
assert_eq!(format!("{:.2e}", -1985), "-1.99e3");
assert_eq!(format!("{:.2e}", -1965), "-1.97e3");
assert_eq!(format!("{:.2e}", -1945), "-1.95e3");
assert_eq!(format!("{:.2e}", -1925), "-1.93e3");
assert_eq!(format!("{:.2e}", -1905), "-1.91e3");
assert_eq!(format!("{:.2e}", -1885), "-1.89e3");
assert_eq!(format!("{:.2e}", -1865), "-1.87e3");
assert_eq!(format!("{:.2e}", -1845), "-1.85e3");
assert_eq!(format!("{:.2e}", -1825), "-1.83e3");
assert_eq!(format!("{:.2e}", -1805), "-1.81e3");
assert_eq!(format!("{:.2e}", -1785), "-1.79e3");
assert_eq!(format!("{:.2e}", -1765), "-1.77e3");
assert_eq!(format!("{:.2e}", -1745), "-1.75e3");
assert_eq!(format!("{:.2e}", -1725), "-1.73e3");
assert_eq!(format!("{:.2e}", -1705), "-1.71e3");
assert_eq!(format!("{:.2e}", -1685), "-1.69e3");
assert_eq!(format!("{:.2e}", -1665), "-1.67e3");
assert_eq!(format!("{:.2e}", -1645), "-1.65e3");
assert_eq!(format!("{:.2e}", -1625), "-1.63e3");
assert_eq!(format!("{:.2e}", -1605), "-1.61e3");
assert_eq!(format!("{:.2e}", -1585), "-1.59e3");
assert_eq!(format!("{:.2e}", -1565), "-1.57e3");
assert_eq!(format!("{:.2e}", -1545), "-1.55e3");
assert_eq!(format!("{:.2e}", -1525), "-1.53e3");
assert_eq!(format!("{:.2e}", -1505), "-1.51e3");
assert_eq!(format!("{:.2e}", -1485), "-1.49e3");
assert_eq!(format!("{:.2e}", -1465), "-1.47e3");
assert_eq!(format!("{:.2e}", -1445), "-1.45e3");
assert_eq!(format!("{:.2e}", -1425), "-1.43e3");
assert_eq!(format!("{:.2e}", -1405), "-1.41e3");
assert_eq!(format!("{:.2e}", -1385), "-1.39e3");
assert_eq!(format!("{:.2e}", -1365), "-1.37e3");
assert_eq!(format!("{:.2e}", -1345), "-1.35e3");
assert_eq!(format!("{:.2e}", -1325), "-1.33e3");
assert_eq!(format!("{:.2e}", -1305), "-1.31e3");
assert_eq!(format!("{:.2e}", -1285), "-1.29e3");
assert_eq!(format!("{:.2e}", -1265), "-1.27e3");
assert_eq!(format!("{:.2e}", -1245), "-1.25e3");
assert_eq!(format!("{:.2e}", -1225), "-1.23e3");
assert_eq!(format!("{:.2e}", -1205), "-1.21e3");
assert_eq!(format!("{:.2e}", -1185), "-1.19e3");
assert_eq!(format!("{:.2e}", -1165), "-1.17e3");
assert_eq!(format!("{:.2e}", -1145), "-1.15e3");
assert_eq!(format!("{:.2e}", -1125), "-1.13e3");
assert_eq!(format!("{:.2e}", -1105), "-1.11e3");
assert_eq!(format!("{:.2e}", -1085), "-1.09e3");
assert_eq!(format!("{:.2e}", -1065), "-1.07e3");
assert_eq!(format!("{:.2e}", -1045), "-1.05e3");
assert_eq!(format!("{:.2e}", -1025), "-1.03e3");
assert_eq!(format!("{:.2e}", -1005), "-1.01e3");
assert_eq!(format!("{:.2e}", 1005), "1.01e3" );
assert_eq!(format!("{:.2e}", 1025), "1.03e3" );
assert_eq!(format!("{:.2e}", 1045), "1.05e3" );
assert_eq!(format!("{:.2e}", 1065), "1.07e3" );
assert_eq!(format!("{:.2e}", 1085), "1.09e3" );
assert_eq!(format!("{:.2e}", 1105), "1.11e3" );
assert_eq!(format!("{:.2e}", 1125), "1.13e3" );
assert_eq!(format!("{:.2e}", 1145), "1.15e3" );
assert_eq!(format!("{:.2e}", 1165), "1.17e3" );
assert_eq!(format!("{:.2e}", 1185), "1.19e3" );
assert_eq!(format!("{:.2e}", 1205), "1.21e3" );
assert_eq!(format!("{:.2e}", 1225), "1.23e3" );
assert_eq!(format!("{:.2e}", 1245), "1.25e3" );
assert_eq!(format!("{:.2e}", 1265), "1.27e3" );
assert_eq!(format!("{:.2e}", 1285), "1.29e3" );
assert_eq!(format!("{:.2e}", 1305), "1.31e3" );
assert_eq!(format!("{:.2e}", 1325), "1.33e3" );
assert_eq!(format!("{:.2e}", 1345), "1.35e3" );
assert_eq!(format!("{:.2e}", 1365), "1.37e3" );
assert_eq!(format!("{:.2e}", 1385), "1.39e3" );
assert_eq!(format!("{:.2e}", 1405), "1.41e3" );
assert_eq!(format!("{:.2e}", 1425), "1.43e3" );
assert_eq!(format!("{:.2e}", 1445), "1.45e3" );
assert_eq!(format!("{:.2e}", 1465), "1.47e3" );
assert_eq!(format!("{:.2e}", 1485), "1.49e3" );
assert_eq!(format!("{:.2e}", 1505), "1.51e3" );
assert_eq!(format!("{:.2e}", 1525), "1.53e3" );
assert_eq!(format!("{:.2e}", 1545), "1.55e3" );
assert_eq!(format!("{:.2e}", 1565), "1.57e3" );
assert_eq!(format!("{:.2e}", 1585), "1.59e3" );
assert_eq!(format!("{:.2e}", 1605), "1.61e3" );
assert_eq!(format!("{:.2e}", 1625), "1.63e3" );
assert_eq!(format!("{:.2e}", 1645), "1.65e3" );
assert_eq!(format!("{:.2e}", 1665), "1.67e3" );
assert_eq!(format!("{:.2e}", 1685), "1.69e3" );
assert_eq!(format!("{:.2e}", 1705), "1.71e3" );
assert_eq!(format!("{:.2e}", 1725), "1.73e3" );
assert_eq!(format!("{:.2e}", 1745), "1.75e3" );
assert_eq!(format!("{:.2e}", 1765), "1.77e3" );
assert_eq!(format!("{:.2e}", 1785), "1.79e3" );
assert_eq!(format!("{:.2e}", 1805), "1.81e3" );
assert_eq!(format!("{:.2e}", 1825), "1.83e3" );
assert_eq!(format!("{:.2e}", 1845), "1.85e3" );
assert_eq!(format!("{:.2e}", 1865), "1.87e3" );
assert_eq!(format!("{:.2e}", 1885), "1.89e3" );
assert_eq!(format!("{:.2e}", 1905), "1.91e3" );
assert_eq!(format!("{:.2e}", 1925), "1.93e3" );
assert_eq!(format!("{:.2e}", 1945), "1.95e3" );
assert_eq!(format!("{:.2e}", 1965), "1.97e3" );
assert_eq!(format!("{:.2e}", 1985), "1.99e3" );
}

#[test]
fn test_format_int_zero() {
assert_eq!(format!("{}", 0), "0");
Expand Down

0 comments on commit e81964e

Please sign in to comment.