diff --git a/include/universal/number/rational/rational_impl.hpp b/include/universal/number/rational/rational_impl.hpp index fd3a3418..626c006c 100644 --- a/include/universal/number/rational/rational_impl.hpp +++ b/include/universal/number/rational/rational_impl.hpp @@ -337,16 +337,27 @@ class rational { uint64_t e{ 0 }, f{ 0 }; bool s{ false }; extractFields(rhs, s, e, f, bits); - + int exponent = static_cast(e - ieee754_parameter::bias); if (e == 0) { // subnormal } else { // normal uint64_t a = f | ieee754_parameter::hmask; uint64_t b = ieee754_parameter::hmask; - int exponent = static_cast(e - ieee754_parameter::bias); -// std::cout << "exponent = " << exponent << '\n'; -// std::cout << "a = " << to_binary(a) << '\n'; -// std::cout << "b = " << to_binary(b) << '\n'; + + //std::cout << "exponent = " << exponent << '\n'; + //std::cout << "a = " << to_binary(a) << '\n'; + //std::cout << "b = " << to_binary(b) << '\n'; + + // remove any redundancy in the representation + uint64_t rr{ 0 }, aa{ a }, bb{ b }; + while (aa % bb > 0ull) { + rr = aa % bb; + aa = bb; + bb = rr; + } + a /= bb; + b /= bb; + if (exponent == 0 && a == b) { n = 1; d = 1; diff --git a/static/rational/conversion/assignment.cpp b/static/rational/conversion/assignment.cpp index a5bb8f61..e480a99b 100644 --- a/static/rational/conversion/assignment.cpp +++ b/static/rational/conversion/assignment.cpp @@ -105,27 +105,30 @@ try { std::string test_suite = "rational float assignment validation"; std::string test_tag = "assignment"; - bool reportTestCases = true; + bool reportTestCases = false; int nrOfFailedTestCases = 0; ReportTestSuiteHeader(test_suite, reportTestCases); #if MANUAL_TESTING - rb64 a,b; + rb16 a,b; a.set(0x02, 0x0A); std::cout << to_binary(a) << '\n'; double da = double(a); b = da; std::cout << to_binary(da) << " : " << da << '\n'; - std::cout << a << '\n'; - std::cout << b << '\n'; + std::cout << to_binary(a) << " : " << a << '\n'; + std::cout << to_binary(b) << " : " << b << '\n'; Ranges(1.0f); // manual exhaustive test // nrOfFailedTestCases += ReportTestResult(ValidateAssignment(reportTestCases), type_tag(rb8()), test_tag); + nrOfFailedTestCases += ReportTestResult(ValidateAssignment(reportTestCases), type_tag(rb16()), test_tag); +// nrOfFailedTestCases += ReportTestResult(ValidateAssignment(reportTestCases), type_tag(rb32()), test_tag); + nrOfFailedTestCases += ReportTestResult(ValidateAssignment(reportTestCases), type_tag(rb64()), test_tag); ReportTestSuiteResults(test_suite, nrOfFailedTestCases); return EXIT_SUCCESS;