diff --git a/static/dd/arithmetic/addition.cpp b/static/dd/arithmetic/addition.cpp index 2bfc9eb9e..3dfaa43a7 100644 --- a/static/dd/arithmetic/addition.cpp +++ b/static/dd/arithmetic/addition.cpp @@ -41,19 +41,25 @@ try { #if MANUAL_TESTING - dd a, b, c, ulpAtOne, onePlusUlp; + dd a, b, c, ulpAtOne, onePlusUlp, onePlusHalfUlp; a = 1.0; ulpAtOne = ulp(1.0); onePlusUlp = a + ulpAtOne; b = ulpAtOne; b /= 2.0; - ReportValue(a, "a",35,32); - ReportValue(onePlusUlp, "1.0 + ulp", 35, 32); - ReportValue(1.0 + b, "1.0 + ulp/2", 35, 32); + ReportValue(a, "1.0",35,32); + ReportValue(ulpAtOne, "ulp", 35, 32); ReportValue(b, "ulp/2", 35, 32); - std::cout << to_pair(onePlusUlp) << '\n'; - std::cout << to_pair(1.0 + b) << '\n'; + ReportValue(onePlusUlp, "1.0 + ulp", 35, 32); + c = a + b; + ReportValue(c, "1.0 + ulp/2", 35, 32); + onePlusHalfUlp = a; + onePlusHalfUlp += ulp(0.5); + + std::cout << "1.0 : " << to_pair(a) << '\n'; + std::cout << "1.0 + ulp(1.0) : " << to_pair(onePlusUlp) << '\n'; + std::cout << "1.0 + ulp(0.5) : " << to_pair(onePlusHalfUlp) << '\n'; ReportTestSuiteResults(test_suite, nrOfFailedTestCases); return EXIT_SUCCESS; // ignore failures diff --git a/static/dd/arithmetic/division.cpp b/static/dd/arithmetic/division.cpp new file mode 100644 index 000000000..b8868e28b --- /dev/null +++ b/static/dd/arithmetic/division.cpp @@ -0,0 +1,95 @@ +// division.cpp: test suite runner for division of doubledouble floating-point values +// +// Copyright (C) 2017 Stillwater Supercomputing, Inc. +// SPDX-License-Identifier: MIT +// +// This file is part of the universal numbers project, which is released under an MIT Open Source license. +#include +#include +#include +#include +#include +#include + +// Regression testing guards: typically set by the cmake configuration, but MANUAL_TESTING is an override +#define MANUAL_TESTING 1 +// REGRESSION_LEVEL_OVERRIDE is set by the cmake file to drive a specific regression intensity +// It is the responsibility of the regression test to organize the tests in a quartile progression. +//#undef REGRESSION_LEVEL_OVERRIDE +#ifndef REGRESSION_LEVEL_OVERRIDE +#undef REGRESSION_LEVEL_1 +#undef REGRESSION_LEVEL_2 +#undef REGRESSION_LEVEL_3 +#undef REGRESSION_LEVEL_4 +#define REGRESSION_LEVEL_1 1 +#define REGRESSION_LEVEL_2 1 +#define REGRESSION_LEVEL_3 1 +#define REGRESSION_LEVEL_4 1 +#endif + +int main() +try { + using namespace sw::universal; + + std::string test_suite = "doubledouble division validation"; + std::string test_tag = "doubledouble division"; + bool reportTestCases = false; + int nrOfFailedTestCases = 0; + + ReportTestSuiteHeader(test_suite, reportTestCases); + +#if MANUAL_TESTING + + + + ReportTestSuiteResults(test_suite, nrOfFailedTestCases); + return EXIT_SUCCESS; // ignore failures +#else // !MANUAL_TESTING + +#if REGRESSION_LEVEL_1 + + constexpr unsigned nrOfRandoms = 1000; + std::stringstream s; + s << test_tag << " " << nrOfRandoms << " random pairs"; + std::string description = s.str(); + nrOfFailedTestCases += ReportTestResult( + VerifyBinaryOperatorThroughRandoms
(reportTestCases, RandomsOp::OPCODE_DIV, nrOfRandoms), + description, + test_tag + ); + +#endif + +#if REGRESSION_LEVEL_2 +#endif + +#if REGRESSION_LEVEL_3 +#endif + +#if REGRESSION_LEVEL_4 +#endif + + ReportTestSuiteResults(test_suite, nrOfFailedTestCases); + return (nrOfFailedTestCases > 0 ? EXIT_FAILURE : EXIT_SUCCESS); +#endif // MANUAL_TESTING +} +catch (char const* msg) { + std::cerr << "Caught ad-hoc exception: " << msg << std::endl; + return EXIT_FAILURE; +} +catch (const sw::universal::universal_arithmetic_exception& err) { + std::cerr << "Caught unexpected universal arithmetic exception : " << err.what() << std::endl; + return EXIT_FAILURE; +} +catch (const sw::universal::universal_internal_exception& err) { + std::cerr << "Caught unexpected universal internal exception: " << err.what() << std::endl; + return EXIT_FAILURE; +} +catch (const std::runtime_error& err) { + std::cerr << "Caught runtime exception: " << err.what() << std::endl; + return EXIT_FAILURE; +} +catch (...) { + std::cerr << "Caught unknown exception" << std::endl; + return EXIT_FAILURE; +} diff --git a/static/dd/arithmetic/multiplication.cpp b/static/dd/arithmetic/multiplication.cpp index 89e2be72b..763879833 100644 --- a/static/dd/arithmetic/multiplication.cpp +++ b/static/dd/arithmetic/multiplication.cpp @@ -43,17 +43,21 @@ try { dd a, b, c, d; - unsigned labelWidth = 40; + constexpr unsigned labelWidth = 40; a.assign("0.1"); - ReportValue(a, "0.1", labelWidth = 40, 32); + ReportValue(a, "0.1", labelWidth, 32); b.assign("10"); - ReportValue(b, "10.0", labelWidth = 40, 32); + ReportValue(b, "10.0", labelWidth, 32); + c = a * b; + ReportValue(c, "1.0", labelWidth, 32); + std::cout << '\n'; + std::string _third("0.333333333333333333333333333333333"); c.assign(_third); - ReportValue(c, _third, labelWidth = 40, 32); + ReportValue(c, _third, labelWidth, 32); - d = c;; + d = c; for (int i = 0; i < 53; ++i) { std::string value = std::string("0.33333... * ") + std::to_string(i) + std::string(" * 0.1"); ReportValue(d, value, labelWidth, 32); @@ -78,7 +82,7 @@ try { s << test_tag << " " << nrOfRandoms << " random pairs"; std::string description = s.str(); nrOfFailedTestCases += ReportTestResult( - VerifyBinaryOperatorThroughRandoms
(reportTestCases, RandomsOp::OPCODE_ADD, nrOfRandoms), + VerifyBinaryOperatorThroughRandoms
(reportTestCases, RandomsOp::OPCODE_MUL, nrOfRandoms), description, test_tag ); diff --git a/static/dd/arithmetic/subtraction.cpp b/static/dd/arithmetic/subtraction.cpp new file mode 100644 index 000000000..3e7312071 --- /dev/null +++ b/static/dd/arithmetic/subtraction.cpp @@ -0,0 +1,114 @@ +// subtraction.cpp: test suite runner for subtraction of doubledouble floating-point values +// +// Copyright (C) 2017 Stillwater Supercomputing, Inc. +// SPDX-License-Identifier: MIT +// +// This file is part of the universal numbers project, which is released under an MIT Open Source license. +#include +#include +#include +#include +#include +#include +#include + +// Regression testing guards: typically set by the cmake configuration, but MANUAL_TESTING is an override +#define MANUAL_TESTING 1 +// REGRESSION_LEVEL_OVERRIDE is set by the cmake file to drive a specific regression intensity +// It is the responsibility of the regression test to organize the tests in a quartile progression. +//#undef REGRESSION_LEVEL_OVERRIDE +#ifndef REGRESSION_LEVEL_OVERRIDE +#undef REGRESSION_LEVEL_1 +#undef REGRESSION_LEVEL_2 +#undef REGRESSION_LEVEL_3 +#undef REGRESSION_LEVEL_4 +#define REGRESSION_LEVEL_1 1 +#define REGRESSION_LEVEL_2 1 +#define REGRESSION_LEVEL_3 1 +#define REGRESSION_LEVEL_4 1 +#endif + +int main() +try { + using namespace sw::universal; + + std::string test_suite = "doubledouble subtraction validation"; + std::string test_tag = "doubledouble subtraction"; + bool reportTestCases = false; + int nrOfFailedTestCases = 0; + + ReportTestSuiteHeader(test_suite, reportTestCases); + +#if MANUAL_TESTING + + dd a, b, c, ulpAtOne, oneMinusUlp, oneMinusHalfUlp; + + a = 1.0; + ulpAtOne = ulp(1.0); + oneMinusUlp = a - ulpAtOne; + b = ulpAtOne; + b /= 2.0; + ReportValue(a, "1.0",35,32); + ReportValue(ulpAtOne, "ulp", 35, 32); + ReportValue(b, "ulp/2", 35, 32); + ReportValue(oneMinusUlp, "1.0 - ulp", 35, 32); + c = a + b; + ReportValue(c, "1.0 - ulp/2", 35, 32); + oneMinusHalfUlp = a; + oneMinusHalfUlp += ulp(0.5); + + std::cout << "1.0 : " << to_pair(a) << '\n'; + std::cout << "1.0 - ulp(1.0) : " << to_pair(oneMinusUlp) << '\n'; + std::cout << "1.0 - ulp(0.5) : " << to_pair(oneMinusHalfUlp) << '\n'; + + ReportTestSuiteResults(test_suite, nrOfFailedTestCases); + return EXIT_SUCCESS; // ignore failures +#else // !MANUAL_TESTING + +#if REGRESSION_LEVEL_1 + + constexpr unsigned nrOfRandoms = 1000; + std::stringstream s; + s << test_tag << " " << nrOfRandoms << " random pairs"; + std::string description = s.str(); + nrOfFailedTestCases += ReportTestResult( + VerifyBinaryOperatorThroughRandoms
(reportTestCases, RandomsOp::OPCODE_SUB, nrOfRandoms), + description, + test_tag + ); + +#endif + +#if REGRESSION_LEVEL_2 +#endif + +#if REGRESSION_LEVEL_3 +#endif + +#if REGRESSION_LEVEL_4 +#endif + + ReportTestSuiteResults(test_suite, nrOfFailedTestCases); + return (nrOfFailedTestCases > 0 ? EXIT_FAILURE : EXIT_SUCCESS); +#endif // MANUAL_TESTING +} +catch (char const* msg) { + std::cerr << "Caught ad-hoc exception: " << msg << std::endl; + return EXIT_FAILURE; +} +catch (const sw::universal::universal_arithmetic_exception& err) { + std::cerr << "Caught unexpected universal arithmetic exception : " << err.what() << std::endl; + return EXIT_FAILURE; +} +catch (const sw::universal::universal_internal_exception& err) { + std::cerr << "Caught unexpected universal internal exception: " << err.what() << std::endl; + return EXIT_FAILURE; +} +catch (const std::runtime_error& err) { + std::cerr << "Caught runtime exception: " << err.what() << std::endl; + return EXIT_FAILURE; +} +catch (...) { + std::cerr << "Caught unknown exception" << std::endl; + return EXIT_FAILURE; +}