From 0647635f5afa8c259a933ab31f7626ca65f539ca Mon Sep 17 00:00:00 2001 From: James Dietz Date: Fri, 27 Oct 2023 17:14:40 -0400 Subject: [PATCH] round to even --- library/core/src/fmt/num.rs | 9 +- library/core/tests/fmt/num.rs | 435 +++++++++++++++++----------------- 2 files changed, 220 insertions(+), 224 deletions(-) diff --git a/library/core/src/fmt/num.rs b/library/core/src/fmt/num.rs index a1467384c9c02..10f6775f31d65 100644 --- a/library/core/src/fmt/num.rs +++ b/library/core/src/fmt/num.rs @@ -330,20 +330,19 @@ macro_rules! impl_Exp { if subtracted_precision != 0 { let rem = n % 10; n /= 10; + let last_digit_odd = n % 2 != 0; exponent += 1; - // round up last digit - if rem >= 5 { + // round up last digit, round to even on a tie + if rem > 5 || (rem == 5 && last_digit_odd) { n += 1; // if the digit is rounded to the next power // instead adjust the exponent - if n % 10 == 0 { + if n.ilog10() > (n - 1).ilog10() { n /= 10; exponent += 1; } } - // n = 100 } - // assert!(n == 666, "{}\n{}\n{}\n",n, exponent, added_precision); (n, exponent, exponent, added_precision) }; diff --git a/library/core/tests/fmt/num.rs b/library/core/tests/fmt/num.rs index 540f306e8f6dd..50505744594e2 100644 --- a/library/core/tests/fmt/num.rs +++ b/library/core/tests/fmt/num.rs @@ -150,10 +150,7 @@ fn test_format_int_exp_precision() { // 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"); @@ -208,33 +205,33 @@ fn new_test() { 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}", -850), "-8e2"); + assert_eq!(format!("{:.0e}", -650), "-6e2"); + assert_eq!(format!("{:.0e}", -450), "-4e2"); + assert_eq!(format!("{:.0e}", -250), "-2e2"); 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}", -85), "-8e1"); + assert_eq!(format!("{:.0e}", -65), "-6e1"); + assert_eq!(format!("{:.0e}", -45), "-4e1"); + assert_eq!(format!("{:.0e}", -25), "-2e1"); + assert_eq!(format!("{:.0e}", 25), "2e1"); + assert_eq!(format!("{:.0e}", 45), "4e1"); + assert_eq!(format!("{:.0e}", 65), "6e1"); + assert_eq!(format!("{:.0e}", 85), "8e1"); 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}", 250), "2e2"); + assert_eq!(format!("{:.0e}", 450), "4e2"); + assert_eq!(format!("{:.0e}", 650), "6e2"); + assert_eq!(format!("{:.0e}", 850), "8e2"); assert_eq!(format!("{:.0e}", 950), "1e3"); assert_eq!(format!("{:.0e}", 951), "1e3"); assert_eq!(format!("{:.0e}", 952), "1e3"); @@ -285,216 +282,216 @@ fn new_test() { 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}", -1850), "-1.8e3"); + assert_eq!(format!("{:.1e}", -1650), "-1.6e3"); + assert_eq!(format!("{:.1e}", -1450), "-1.4e3"); + assert_eq!(format!("{:.1e}", -1250), "-1.2e3"); + assert_eq!(format!("{:.1e}", -1050), "-1.0e3"); 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}", -985), "-9.8e2"); + assert_eq!(format!("{:.1e}", -965), "-9.6e2"); + assert_eq!(format!("{:.1e}", -945), "-9.4e2"); + assert_eq!(format!("{:.1e}", -925), "-9.2e2"); + assert_eq!(format!("{:.1e}", -905), "-9.0e2"); + assert_eq!(format!("{:.1e}", -885), "-8.8e2"); + assert_eq!(format!("{:.1e}", -865), "-8.6e2"); + assert_eq!(format!("{:.1e}", -845), "-8.4e2"); + assert_eq!(format!("{:.1e}", -825), "-8.2e2"); + assert_eq!(format!("{:.1e}", -805), "-8.0e2"); + assert_eq!(format!("{:.1e}", -785), "-7.8e2"); + assert_eq!(format!("{:.1e}", -765), "-7.6e2"); + assert_eq!(format!("{:.1e}", -745), "-7.4e2"); + assert_eq!(format!("{:.1e}", -725), "-7.2e2"); + assert_eq!(format!("{:.1e}", -705), "-7.0e2"); + assert_eq!(format!("{:.1e}", -685), "-6.8e2"); + assert_eq!(format!("{:.1e}", -665), "-6.6e2"); + assert_eq!(format!("{:.1e}", -645), "-6.4e2"); + assert_eq!(format!("{:.1e}", -625), "-6.2e2"); + assert_eq!(format!("{:.1e}", -605), "-6.0e2"); + assert_eq!(format!("{:.1e}", -585), "-5.8e2"); + assert_eq!(format!("{:.1e}", -565), "-5.6e2"); + assert_eq!(format!("{:.1e}", -545), "-5.4e2"); + assert_eq!(format!("{:.1e}", -525), "-5.2e2"); + assert_eq!(format!("{:.1e}", -505), "-5.0e2"); + assert_eq!(format!("{:.1e}", -485), "-4.8e2"); + assert_eq!(format!("{:.1e}", -465), "-4.6e2"); + assert_eq!(format!("{:.1e}", -445), "-4.4e2"); + assert_eq!(format!("{:.1e}", -425), "-4.2e2"); + assert_eq!(format!("{:.1e}", -405), "-4.0e2"); + assert_eq!(format!("{:.1e}", -385), "-3.8e2"); + assert_eq!(format!("{:.1e}", -365), "-3.6e2"); + assert_eq!(format!("{:.1e}", -345), "-3.4e2"); + assert_eq!(format!("{:.1e}", -325), "-3.2e2"); + assert_eq!(format!("{:.1e}", -305), "-3.0e2"); + assert_eq!(format!("{:.1e}", -285), "-2.8e2"); + assert_eq!(format!("{:.1e}", -265), "-2.6e2"); + assert_eq!(format!("{:.1e}", -245), "-2.4e2"); + assert_eq!(format!("{:.1e}", -225), "-2.2e2"); + assert_eq!(format!("{:.1e}", -205), "-2.0e2"); + assert_eq!(format!("{:.1e}", -185), "-1.8e2"); + assert_eq!(format!("{:.1e}", -165), "-1.6e2"); + assert_eq!(format!("{:.1e}", -145), "-1.4e2"); + assert_eq!(format!("{:.1e}", -125), "-1.2e2"); + assert_eq!(format!("{:.1e}", -105), "-1.0e2"); + assert_eq!(format!("{:.1e}", 105), "1.0e2"); + assert_eq!(format!("{:.1e}", 125), "1.2e2"); + assert_eq!(format!("{:.1e}", 145), "1.4e2"); + assert_eq!(format!("{:.1e}", 165), "1.6e2"); + assert_eq!(format!("{:.1e}", 185), "1.8e2"); + assert_eq!(format!("{:.1e}", 205), "2.0e2"); + assert_eq!(format!("{:.1e}", 225), "2.2e2"); + assert_eq!(format!("{:.1e}", 245), "2.4e2"); + assert_eq!(format!("{:.1e}", 265), "2.6e2"); + assert_eq!(format!("{:.1e}", 285), "2.8e2"); + assert_eq!(format!("{:.1e}", 305), "3.0e2"); + assert_eq!(format!("{:.1e}", 325), "3.2e2"); + assert_eq!(format!("{:.1e}", 345), "3.4e2"); + assert_eq!(format!("{:.1e}", 365), "3.6e2"); + assert_eq!(format!("{:.1e}", 385), "3.8e2"); + assert_eq!(format!("{:.1e}", 405), "4.0e2"); + assert_eq!(format!("{:.1e}", 425), "4.2e2"); + assert_eq!(format!("{:.1e}", 445), "4.4e2"); + assert_eq!(format!("{:.1e}", 465), "4.6e2"); + assert_eq!(format!("{:.1e}", 485), "4.8e2"); + assert_eq!(format!("{:.1e}", 505), "5.0e2"); + assert_eq!(format!("{:.1e}", 525), "5.2e2"); + assert_eq!(format!("{:.1e}", 545), "5.4e2"); + assert_eq!(format!("{:.1e}", 565), "5.6e2"); + assert_eq!(format!("{:.1e}", 585), "5.8e2"); + assert_eq!(format!("{:.1e}", 605), "6.0e2"); + assert_eq!(format!("{:.1e}", 625), "6.2e2"); + assert_eq!(format!("{:.1e}", 645), "6.4e2"); + assert_eq!(format!("{:.1e}", 665), "6.6e2"); + assert_eq!(format!("{:.1e}", 685), "6.8e2"); + assert_eq!(format!("{:.1e}", 705), "7.0e2"); + assert_eq!(format!("{:.1e}", 725), "7.2e2"); + assert_eq!(format!("{:.1e}", 745), "7.4e2"); + assert_eq!(format!("{:.1e}", 765), "7.6e2"); + assert_eq!(format!("{:.1e}", 785), "7.8e2"); + assert_eq!(format!("{:.1e}", 805), "8.0e2"); + assert_eq!(format!("{:.1e}", 825), "8.2e2"); + assert_eq!(format!("{:.1e}", 845), "8.4e2"); + assert_eq!(format!("{:.1e}", 865), "8.6e2"); + assert_eq!(format!("{:.1e}", 885), "8.8e2"); + assert_eq!(format!("{:.1e}", 905), "9.0e2"); + assert_eq!(format!("{:.1e}", 925), "9.2e2"); + assert_eq!(format!("{:.1e}", 945), "9.4e2"); + assert_eq!(format!("{:.1e}", 965), "9.6e2"); + assert_eq!(format!("{:.1e}", 985), "9.8e2"); 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" ); + assert_eq!(format!("{:.1e}", 1050), "1.0e3"); + assert_eq!(format!("{:.1e}", 1250), "1.2e3"); + assert_eq!(format!("{:.1e}", 1450), "1.4e3"); + assert_eq!(format!("{:.1e}", 1650), "1.6e3"); + assert_eq!(format!("{:.1e}", 1850), "1.8e3"); + assert_eq!(format!("{:.2e}", -1985), "-1.98e3"); + assert_eq!(format!("{:.2e}", -1965), "-1.96e3"); + assert_eq!(format!("{:.2e}", -1945), "-1.94e3"); + assert_eq!(format!("{:.2e}", -1925), "-1.92e3"); + assert_eq!(format!("{:.2e}", -1905), "-1.90e3"); + assert_eq!(format!("{:.2e}", -1885), "-1.88e3"); + assert_eq!(format!("{:.2e}", -1865), "-1.86e3"); + assert_eq!(format!("{:.2e}", -1845), "-1.84e3"); + assert_eq!(format!("{:.2e}", -1825), "-1.82e3"); + assert_eq!(format!("{:.2e}", -1805), "-1.80e3"); + assert_eq!(format!("{:.2e}", -1785), "-1.78e3"); + assert_eq!(format!("{:.2e}", -1765), "-1.76e3"); + assert_eq!(format!("{:.2e}", -1745), "-1.74e3"); + assert_eq!(format!("{:.2e}", -1725), "-1.72e3"); + assert_eq!(format!("{:.2e}", -1705), "-1.70e3"); + assert_eq!(format!("{:.2e}", -1685), "-1.68e3"); + assert_eq!(format!("{:.2e}", -1665), "-1.66e3"); + assert_eq!(format!("{:.2e}", -1645), "-1.64e3"); + assert_eq!(format!("{:.2e}", -1625), "-1.62e3"); + assert_eq!(format!("{:.2e}", -1605), "-1.60e3"); + assert_eq!(format!("{:.2e}", -1585), "-1.58e3"); + assert_eq!(format!("{:.2e}", -1565), "-1.56e3"); + assert_eq!(format!("{:.2e}", -1545), "-1.54e3"); + assert_eq!(format!("{:.2e}", -1525), "-1.52e3"); + assert_eq!(format!("{:.2e}", -1505), "-1.50e3"); + assert_eq!(format!("{:.2e}", -1485), "-1.48e3"); + assert_eq!(format!("{:.2e}", -1465), "-1.46e3"); + assert_eq!(format!("{:.2e}", -1445), "-1.44e3"); + assert_eq!(format!("{:.2e}", -1425), "-1.42e3"); + assert_eq!(format!("{:.2e}", -1405), "-1.40e3"); + assert_eq!(format!("{:.2e}", -1385), "-1.38e3"); + assert_eq!(format!("{:.2e}", -1365), "-1.36e3"); + assert_eq!(format!("{:.2e}", -1345), "-1.34e3"); + assert_eq!(format!("{:.2e}", -1325), "-1.32e3"); + assert_eq!(format!("{:.2e}", -1305), "-1.30e3"); + assert_eq!(format!("{:.2e}", -1285), "-1.28e3"); + assert_eq!(format!("{:.2e}", -1265), "-1.26e3"); + assert_eq!(format!("{:.2e}", -1245), "-1.24e3"); + assert_eq!(format!("{:.2e}", -1225), "-1.22e3"); + assert_eq!(format!("{:.2e}", -1205), "-1.20e3"); + assert_eq!(format!("{:.2e}", -1185), "-1.18e3"); + assert_eq!(format!("{:.2e}", -1165), "-1.16e3"); + assert_eq!(format!("{:.2e}", -1145), "-1.14e3"); + assert_eq!(format!("{:.2e}", -1125), "-1.12e3"); + assert_eq!(format!("{:.2e}", -1105), "-1.10e3"); + assert_eq!(format!("{:.2e}", -1085), "-1.08e3"); + assert_eq!(format!("{:.2e}", -1065), "-1.06e3"); + assert_eq!(format!("{:.2e}", -1045), "-1.04e3"); + assert_eq!(format!("{:.2e}", -1025), "-1.02e3"); + assert_eq!(format!("{:.2e}", -1005), "-1.00e3"); + assert_eq!(format!("{:.2e}", 1005), "1.00e3" ); + assert_eq!(format!("{:.2e}", 1025), "1.02e3" ); + assert_eq!(format!("{:.2e}", 1045), "1.04e3" ); + assert_eq!(format!("{:.2e}", 1065), "1.06e3" ); + assert_eq!(format!("{:.2e}", 1085), "1.08e3" ); + assert_eq!(format!("{:.2e}", 1105), "1.10e3" ); + assert_eq!(format!("{:.2e}", 1125), "1.12e3" ); + assert_eq!(format!("{:.2e}", 1145), "1.14e3" ); + assert_eq!(format!("{:.2e}", 1165), "1.16e3" ); + assert_eq!(format!("{:.2e}", 1185), "1.18e3" ); + assert_eq!(format!("{:.2e}", 1205), "1.20e3" ); + assert_eq!(format!("{:.2e}", 1225), "1.22e3" ); + assert_eq!(format!("{:.2e}", 1245), "1.24e3" ); + assert_eq!(format!("{:.2e}", 1265), "1.26e3" ); + assert_eq!(format!("{:.2e}", 1285), "1.28e3" ); + assert_eq!(format!("{:.2e}", 1305), "1.30e3" ); + assert_eq!(format!("{:.2e}", 1325), "1.32e3" ); + assert_eq!(format!("{:.2e}", 1345), "1.34e3" ); + assert_eq!(format!("{:.2e}", 1365), "1.36e3" ); + assert_eq!(format!("{:.2e}", 1385), "1.38e3" ); + assert_eq!(format!("{:.2e}", 1405), "1.40e3" ); + assert_eq!(format!("{:.2e}", 1425), "1.42e3" ); + assert_eq!(format!("{:.2e}", 1445), "1.44e3" ); + assert_eq!(format!("{:.2e}", 1465), "1.46e3" ); + assert_eq!(format!("{:.2e}", 1485), "1.48e3" ); + assert_eq!(format!("{:.2e}", 1505), "1.50e3" ); + assert_eq!(format!("{:.2e}", 1525), "1.52e3" ); + assert_eq!(format!("{:.2e}", 1545), "1.54e3" ); + assert_eq!(format!("{:.2e}", 1565), "1.56e3" ); + assert_eq!(format!("{:.2e}", 1585), "1.58e3" ); + assert_eq!(format!("{:.2e}", 1605), "1.60e3" ); + assert_eq!(format!("{:.2e}", 1625), "1.62e3" ); + assert_eq!(format!("{:.2e}", 1645), "1.64e3" ); + assert_eq!(format!("{:.2e}", 1665), "1.66e3" ); + assert_eq!(format!("{:.2e}", 1685), "1.68e3" ); + assert_eq!(format!("{:.2e}", 1705), "1.70e3" ); + assert_eq!(format!("{:.2e}", 1725), "1.72e3" ); + assert_eq!(format!("{:.2e}", 1745), "1.74e3" ); + assert_eq!(format!("{:.2e}", 1765), "1.76e3" ); + assert_eq!(format!("{:.2e}", 1785), "1.78e3" ); + assert_eq!(format!("{:.2e}", 1805), "1.80e3" ); + assert_eq!(format!("{:.2e}", 1825), "1.82e3" ); + assert_eq!(format!("{:.2e}", 1845), "1.84e3" ); + assert_eq!(format!("{:.2e}", 1865), "1.86e3" ); + assert_eq!(format!("{:.2e}", 1885), "1.88e3" ); + assert_eq!(format!("{:.2e}", 1905), "1.90e3" ); + assert_eq!(format!("{:.2e}", 1925), "1.92e3" ); + assert_eq!(format!("{:.2e}", 1945), "1.94e3" ); + assert_eq!(format!("{:.2e}", 1965), "1.96e3" ); + assert_eq!(format!("{:.2e}", 1985), "1.98e3" ); } #[test]