diff --git a/src/simulator/high-precision-128.cc b/src/simulator/high-precision-128.cc index 24a1de74c..bad6a0399 100644 --- a/src/simulator/high-precision-128.cc +++ b/src/simulator/high-precision-128.cc @@ -39,7 +39,7 @@ int HighPrecision::m_nslowgets = 0; int HighPrecision::m_ndivs = 0; int HighPrecision::m_nconversions = 0; -void +void HighPrecision::PrintStats (void) { double nadds = m_nfastadds + m_nslowadds; @@ -53,25 +53,25 @@ HighPrecision::PrintStats (void) double fast_mul_ratio = m_nfastmuls / nmuls; double fast_get_ratio = m_nfastgets / ngets; - std::cout << - "add="< (this)->EnsureSlow (); @@ -278,7 +278,7 @@ HighPrecision::SlowCompare (HighPrecision const &o) const #include "ns3/test.h" #define CHECK_EXPECTED(a,b) \ - NS_TEST_ASSERT_MSG_EQ(a.GetInteger(),b,"Arithmetic failure: " << (a.GetInteger()) << "!=" << (b)) + NS_TEST_ASSERT_MSG_EQ (a.GetInteger (),b,"Arithmetic failure: " << (a.GetInteger ()) << "!=" << (b)) #define V(v) \ HighPrecision (v, false) @@ -294,8 +294,9 @@ public: Hp128ArithmeticTestCase::Hp128ArithmeticTestCase () : TestCase ("Check basic arithmetic operations") -{} -bool +{ +} +bool Hp128ArithmeticTestCase::DoRun (void) { HighPrecision a, b; @@ -306,103 +307,103 @@ Hp128ArithmeticTestCase::DoRun (void) CHECK_EXPECTED (a, 0); a = V (1); - a.Sub (V(2)); + a.Sub (V (2)); CHECK_EXPECTED (a, -1); a = V (1); - a.Sub (V(3)); + a.Sub (V (3)); CHECK_EXPECTED (a, -2); a = V (1); - a.Sub (V(-1)); + a.Sub (V (-1)); CHECK_EXPECTED (a, 2); a = V (1); - a.Sub (V(-2)); + a.Sub (V (-2)); CHECK_EXPECTED (a, 3); a = V (-3); - a.Sub (V(-4)); + a.Sub (V (-4)); CHECK_EXPECTED (a, 1); a = V (-2); - a.Sub (V(3)); + a.Sub (V (3)); CHECK_EXPECTED (a, -5); a = V (1); - a.Add (V(2)); + a.Add (V (2)); CHECK_EXPECTED (a, 3); a = V (1); - a.Add (V(-3)); + a.Add (V (-3)); CHECK_EXPECTED (a, -2); a = V (0); - a.Add (V(0)); + a.Add (V (0)); CHECK_EXPECTED (a, 0); a = V (0); - a.Mul (V(0)); + a.Mul (V (0)); CHECK_EXPECTED (a, 0); a = V (0); - a.Mul (V(1)); + a.Mul (V (1)); CHECK_EXPECTED (a, 0); a = V (0); - a.Mul (V(-1)); + a.Mul (V (-1)); CHECK_EXPECTED (a, 0); a = V (1); - a.Mul (V(0)); + a.Mul (V (0)); CHECK_EXPECTED (a, 0); a = V (1); - a.Mul (V(1)); + a.Mul (V (1)); CHECK_EXPECTED (a, 1); a = V (1); - a.Mul (V(-1)); + a.Mul (V (-1)); CHECK_EXPECTED (a, -1); a = V (-1); - a.Mul (V(-1)); + a.Mul (V (-1)); CHECK_EXPECTED (a, 1); a = V (0); - a.Mul (V(1)); + a.Mul (V (1)); CHECK_EXPECTED (a, 0); a = V (0); - a.Mul (V(-1)); + a.Mul (V (-1)); CHECK_EXPECTED (a, 0); a = V (1); - a.Mul (V(1)); + a.Mul (V (1)); CHECK_EXPECTED (a, 1); a = V (1); - a.Mul (V(-1)); + a.Mul (V (-1)); CHECK_EXPECTED (a, -1); a = V (-1); - a.Mul (V(1)); + a.Mul (V (1)); CHECK_EXPECTED (a, -1); a = V (-1); - a.Mul (V(-1)); + a.Mul (V (-1)); CHECK_EXPECTED (a, 1); a = V (2); - a.Mul (V(3)); - a.Div (V(3)); + a.Mul (V (3)); + a.Div (V (3)); CHECK_EXPECTED (a, 2); // Below, the division loses precision because 2/3 is not // representable exactly in 64.64 integers. So, we got // something super close but the final rounding kills us. a = V (2); - a.Div (V(3)); - a.Mul (V(3)); + a.Div (V (3)); + a.Mul (V (3)); CHECK_EXPECTED (a, 1); // The example below shows that we really do not lose // much precision internally: it is almost always the // final conversion which loses precision. a = V (2000000000); - a.Div (V(3)); - a.Mul (V(3)); + a.Div (V (3)); + a.Mul (V (3)); CHECK_EXPECTED (a, 1999999999); return false; @@ -411,30 +412,31 @@ Hp128ArithmeticTestCase::DoRun (void) class Hp128Bug455TestCase : public TestCase { public: - Hp128Bug455TestCase(); + Hp128Bug455TestCase (); virtual bool DoRun (void); }; -Hp128Bug455TestCase::Hp128Bug455TestCase() - : TestCase("Test case for bug 455") -{} -bool +Hp128Bug455TestCase::Hp128Bug455TestCase () + : TestCase ("Test case for bug 455") +{ +} +bool Hp128Bug455TestCase::DoRun (void) { HighPrecision a = HighPrecision (0.1); a.Div (HighPrecision (1.25)); NS_TEST_ASSERT_MSG_EQ (a.GetDouble (), 0.08, "The original testcase"); a = HighPrecision (0.5); - a.Mul(HighPrecision (5)); + a.Mul (HighPrecision (5)); NS_TEST_ASSERT_MSG_EQ (a.GetDouble (), 2.5, "Simple test for multiplication"); a = HighPrecision (-0.5); - a.Mul(HighPrecision (5)); + a.Mul (HighPrecision (5)); NS_TEST_ASSERT_MSG_EQ (a.GetDouble (), -2.5, "Test sign, first operation negative"); a = HighPrecision (-0.5); - a.Mul(HighPrecision (-5)); + a.Mul (HighPrecision (-5)); NS_TEST_ASSERT_MSG_EQ (a.GetDouble (), 2.5, "both operands negative"); a = HighPrecision (0.5); - a.Mul(HighPrecision (-5)); + a.Mul (HighPrecision (-5)); NS_TEST_ASSERT_MSG_EQ (a.GetDouble (), -2.5, "only second operand negative"); return false; @@ -444,30 +446,31 @@ Hp128Bug455TestCase::DoRun (void) class Hp128Bug863TestCase : public TestCase { public: - Hp128Bug863TestCase(); + Hp128Bug863TestCase (); virtual bool DoRun (void); }; -Hp128Bug863TestCase::Hp128Bug863TestCase() - : TestCase("Test case for bug 863") -{} -bool +Hp128Bug863TestCase::Hp128Bug863TestCase () + : TestCase ("Test case for bug 863") +{ +} +bool Hp128Bug863TestCase::DoRun (void) { HighPrecision a = HighPrecision (0.9); a.Div (HighPrecision (1)); NS_TEST_ASSERT_MSG_EQ (a.GetDouble (), 0.9, "The original testcase"); a = HighPrecision (0.5); - a.Div(HighPrecision (0.5)); + a.Div (HighPrecision (0.5)); NS_TEST_ASSERT_MSG_EQ (a.GetDouble (), 1.0, "Simple test for division"); a = HighPrecision (-0.5); - a.Div(HighPrecision (0.5)); + a.Div (HighPrecision (0.5)); NS_TEST_ASSERT_MSG_EQ (a.GetDouble (), -1.0, "first argument negative"); a = HighPrecision (0.5); - a.Div(HighPrecision (-0.5)); + a.Div (HighPrecision (-0.5)); NS_TEST_ASSERT_MSG_EQ (a.GetDouble (), -1.0, "second argument negative"); a = HighPrecision (-0.5); - a.Div(HighPrecision (-0.5)); + a.Div (HighPrecision (-0.5)); NS_TEST_ASSERT_MSG_EQ (a.GetDouble (), 1.0, "both arguments negative"); return false; @@ -476,12 +479,12 @@ Hp128Bug863TestCase::DoRun (void) static class HighPrecision128TestSuite : public TestSuite { public: - HighPrecision128TestSuite() + HighPrecision128TestSuite () : TestSuite ("high-precision-128", UNIT) { - AddTestCase (new Hp128ArithmeticTestCase()); - AddTestCase (new Hp128Bug455TestCase()); - AddTestCase (new Hp128Bug863TestCase()); + AddTestCase (new Hp128ArithmeticTestCase ()); + AddTestCase (new Hp128Bug455TestCase ()); + AddTestCase (new Hp128Bug863TestCase ()); } } g_highPrecision128TestSuite;