Skip to content

Commit

Permalink
completing arithmetic regression test skeletons for double-double
Browse files Browse the repository at this point in the history
  • Loading branch information
Ravenwater committed Aug 5, 2024
1 parent 8d281cf commit 790f889
Show file tree
Hide file tree
Showing 4 changed files with 231 additions and 12 deletions.
18 changes: 12 additions & 6 deletions static/dd/arithmetic/addition.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
95 changes: 95 additions & 0 deletions static/dd/arithmetic/division.cpp
Original file line number Diff line number Diff line change
@@ -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 <universal/utility/directives.hpp>
#include <universal/number/dd/dd.hpp>
#include <universal/number/cfloat/cfloat.hpp>
#include <universal/verification/test_suite.hpp>
#include <universal/verification/test_suite_arithmetic.hpp>
#include <universal/verification/test_suite_randoms.hpp>

// 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<dd>(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;
}
16 changes: 10 additions & 6 deletions static/dd/arithmetic/multiplication.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -78,7 +82,7 @@ try {
s << test_tag << " " << nrOfRandoms << " random pairs";
std::string description = s.str();
nrOfFailedTestCases += ReportTestResult(
VerifyBinaryOperatorThroughRandoms<dd>(reportTestCases, RandomsOp::OPCODE_ADD, nrOfRandoms),
VerifyBinaryOperatorThroughRandoms<dd>(reportTestCases, RandomsOp::OPCODE_MUL, nrOfRandoms),
description,
test_tag
);
Expand Down
114 changes: 114 additions & 0 deletions static/dd/arithmetic/subtraction.cpp
Original file line number Diff line number Diff line change
@@ -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 <universal/utility/directives.hpp>
#include <universal/number/dd/dd.hpp>
#include <universal/number/cfloat/cfloat.hpp>
#include <universal/verification/test_suite.hpp>
#include <universal/verification/test_suite_arithmetic.hpp>
#include <universal/verification/test_suite_randoms.hpp>
#include <universal/verification/cfloat_test_suite.hpp>

// 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<dd>(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;
}

0 comments on commit 790f889

Please sign in to comment.