Skip to content

Commit

Permalink
adding min/max function regression tests for quad-double
Browse files Browse the repository at this point in the history
  • Loading branch information
Ravenwater committed Aug 15, 2024
1 parent e09cc77 commit 92f5666
Show file tree
Hide file tree
Showing 3 changed files with 79 additions and 3 deletions.
4 changes: 2 additions & 2 deletions include/universal/number/qd/math/minmax.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@

namespace sw { namespace universal {

qd min(qd x, qd y) {
qd min(const qd& x, const qd& y) {
return qd(std::min(double(x), double(y)));
}

qd max(qd x, qd y) {
qd max(const qd& x, const qd& y) {
return qd(std::max(double(x), double(y)));
}

Expand Down
2 changes: 1 addition & 1 deletion include/universal/number/qd/mathlib.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
#include <universal/number/qd/math/hyperbolic.hpp>
#include <universal/number/qd/math/hypot.hpp>
#include <universal/number/qd/math/logarithm.hpp>
//#include <universal/number/qd/math/minmax.hpp>
#include <universal/number/qd/math/minmax.hpp>
//#include <universal/number/qd/math/next.hpp>
//#include <universal/number/qd/math/pow.hpp>
#include <universal/number/qd/math/sqrt.hpp>
Expand Down
76 changes: 76 additions & 0 deletions static/qd/math/minmax.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
// minmax.cpp: test suite runner for minmax functions for quad-double (qd) floating-point
//
// 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 <numbers>
#include <universal/number/qd/qd.hpp>
#include <universal/verification/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 = "quad-double mathlib minmax function validation";
std::string test_tag = "min/max";
bool reportTestCases = false;
int nrOfFailedTestCases = 0;

ReportTestSuiteHeader(test_suite, reportTestCases);

#if MANUAL_TESTING

qd x{ 3.0 }, y{ 4.0 };

std::cout << "MIN/MAX FUNCTIONS ARE SHIMS TO DOUBLE\n";
std::cout << "min( " << x << ", " << y << ") = " << min(x, y) << '\n';
std::cout << "max( " << x << ", " << y << ") = " << max(x, y) << '\n';

ReportTestSuiteResults(test_suite, nrOfFailedTestCases);
return EXIT_SUCCESS; // ignore errors
#else


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 92f5666

Please sign in to comment.