From 86f8c8ffc9ff842f150f6ac5a1782f17f6c6d44c Mon Sep 17 00:00:00 2001 From: Ravenwater Date: Fri, 15 Oct 2021 18:25:26 -0400 Subject: [PATCH] bringing areal forward to the new structure --- include/universal/number/areal/areal.hpp | 8 +++ include/universal/number/areal/areal_impl.hpp | 14 +++--- .../verification/areal_test_suite.hpp | 5 +- tests/areal/api/api.cpp | 14 ++---- tests/areal/api/assignment.cpp | 49 +++++++++---------- tests/areal/api/constexpr.cpp | 20 ++------ tests/areal/api/special_cases.cpp | 5 +- tests/areal/arithmetic/addition.cpp | 4 +- tests/areal/conversion/double_conversion.cpp | 5 +- tests/areal/conversion/float_conversion.cpp | 5 +- tests/areal/conversion/sampling.cpp | 5 +- tests/areal/logic/logic.cpp | 3 +- tests/areal/standard/double_precision.cpp | 30 ++---------- tests/areal/standard/half_precision.cpp | 29 ++--------- tests/areal/standard/quad_precision.cpp | 30 ++---------- tests/areal/standard/quarter_precision.cpp | 40 ++------------- tests/areal/standard/single_precision.cpp | 30 ++---------- tests/fixpnt/api/api.cpp | 12 ++--- 18 files changed, 83 insertions(+), 225 deletions(-) diff --git a/include/universal/number/areal/areal.hpp b/include/universal/number/areal/areal.hpp index 83e673f96..fb2cb95d5 100644 --- a/include/universal/number/areal/areal.hpp +++ b/include/universal/number/areal/areal.hpp @@ -6,6 +6,14 @@ #ifndef _AREAL_STANDARD_HEADER_ #define _AREAL_STANDARD_HEADER_ +//////////////////////////////////////////////////////////////////////////////////////// +/// COMPILATION DIRECTIVES TO DIFFERENT COMPILERS + +// compiler specific configuration for long double support +#include +// compiler specific configuration for C++20 bit_cast +#include + //////////////////////////////////////////////////////////////////////////////////////// /// BEHAVIORAL COMPILATION SWITCHES diff --git a/include/universal/number/areal/areal_impl.hpp b/include/universal/number/areal/areal_impl.hpp index 6cc76184f..15b85f4c7 100644 --- a/include/universal/number/areal/areal_impl.hpp +++ b/include/universal/number/areal/areal_impl.hpp @@ -1036,17 +1036,17 @@ class areal { void constexprClassParameters() const { std::cout << "nbits : " << nbits << '\n'; std::cout << "es : " << es << std::endl; - std::cout << "ALLONES : " << to_binary(ALLONES, true) << '\n'; - std::cout << "BLOCK_MASK : " << to_binary(BLOCK_MASK, true) << '\n'; + std::cout << "ALLONES : " << to_binary(ALLONES, bitsInBlock, true) << '\n'; + std::cout << "BLOCK_MASK : " << to_binary(BLOCK_MASK, bitsInBlock, true) << '\n'; std::cout << "nrBlocks : " << nrBlocks << '\n'; std::cout << "bits in MSU : " << bitsInMSU << '\n'; std::cout << "MSU : " << MSU << '\n'; - std::cout << "MSU MASK : " << to_binary(MSU_MASK, true) << '\n'; - std::cout << "SIGN_BIT_MASK : " << to_binary(SIGN_BIT_MASK, true) << '\n'; - std::cout << "LSB_BIT_MASK : " << to_binary(LSB_BIT_MASK, true) << '\n'; + std::cout << "MSU MASK : " << to_binary(MSU_MASK, bitsInBlock, true) << '\n'; + std::cout << "SIGN_BIT_MASK : " << to_binary(SIGN_BIT_MASK, bitsInBlock, true) << '\n'; + std::cout << "LSB_BIT_MASK : " << to_binary(LSB_BIT_MASK, bitsInBlock, true) << '\n'; std::cout << "MSU CAPTURES E : " << (MSU_CAPTURES_E ? "yes\n" : "no\n"); std::cout << "EXP_SHIFT : " << EXP_SHIFT << '\n'; - std::cout << "MSU EXP MASK : " << to_binary(MSU_EXP_MASK, true) << '\n'; + std::cout << "MSU EXP MASK : " << to_binary(MSU_EXP_MASK, bitsInBlock, true) << '\n'; std::cout << "EXP_BIAS : " << EXP_BIAS << '\n'; std::cout << "MAX_EXP : " << MAX_EXP << '\n'; std::cout << "MIN_EXP_NORMAL : " << MIN_EXP_NORMAL << '\n'; @@ -1460,6 +1460,7 @@ inline std::string to_binary(const areal& number, bool nibbleMark return ss.str(); } +#ifdef DEPRECATED // helper to report on BlockType blocks template inline std::string to_binary(const bt& number, bool nibbleMarker) { @@ -1476,6 +1477,7 @@ inline std::string to_binary(const bt& number, bool nibbleMarker) { } return ss.str(); } +#endif /// Magnitude of a scientific notation value (equivalent to turning the sign bit off). template diff --git a/include/universal/verification/areal_test_suite.hpp b/include/universal/verification/areal_test_suite.hpp index 22cbd33f9..2c889bf3a 100644 --- a/include/universal/verification/areal_test_suite.hpp +++ b/include/universal/verification/areal_test_suite.hpp @@ -11,6 +11,7 @@ #include #include // fpclassify, isnormal, issubnormal, isinf, isnan +#include namespace sw::universal { @@ -171,7 +172,7 @@ namespace sw::universal { std::cout << "interval: " << to_binary(previousInterval) << " : " << previousInterval << std::endl; std::cout << "current : " << to_binary(current) << " : " << current << std::endl; std::cout << "interval: " << to_binary(interval) << " : " << interval << std::endl; - std::cout << "delta : " << delta << " : " << to_binary(delta, true) << std::endl; + std::cout << "delta : " << delta << " : " << to_binary(delta) << std::endl; } // da - delta = (prev,current) == previous + ubit = previous interval value testValue = da - delta; @@ -191,7 +192,7 @@ namespace sw::universal { std::cout << "interval: " << to_binary(previousInterval) << " : " << previousInterval << std::endl; std::cout << "current : " << to_binary(current) << " : " << current << std::endl; std::cout << "interval: " << to_binary(interval) << " : " << interval << std::endl; - std::cout << "delta : " << delta << " : " << to_binary(delta, true) << std::endl; + std::cout << "delta : " << delta << " : " << to_binary(delta) << std::endl; } } diff --git a/tests/areal/api/api.cpp b/tests/areal/api/api.cpp index 48abffa16..78ddf08de 100644 --- a/tests/areal/api/api.cpp +++ b/tests/areal/api/api.cpp @@ -12,26 +12,20 @@ #include #include #include -// minimum set of include files to reflect source code dependencies -#include -#include // hex_print and the like + +#include #include #define MANUAL_TESTING 1 #define STRESS_TESTING 0 -int main(int argc, char** argv) +int main() try { using namespace sw::universal; - if (argc > 0) { - std::cout << argv[0] << std::endl; - } - // const size_t RND_TEST_CASES = 0; // no randoms, 8-bit posits can be done exhaustively - + std::cout << "areal<> Application Programming Interface tests" << std::endl; int nrOfFailedTestCases = 0; - std::cout << "areal<> Application Programming Interface tests" << std::endl; #if MANUAL_TESTING diff --git a/tests/areal/api/assignment.cpp b/tests/areal/api/assignment.cpp index f06af98ea..cf53885f6 100644 --- a/tests/areal/api/assignment.cpp +++ b/tests/areal/api/assignment.cpp @@ -15,11 +15,8 @@ #define AREAL_THROW_ARITHMETIC_EXCEPTION 0 // enabling tracing #define TRACE_CONVERSION 0 -// minimum set of include files to reflect source code dependencies -#include -// fixed-point type manipulators such as pretty printers -#include -#include + +#include #include #include @@ -438,11 +435,12 @@ int main(int argc, char** argv) try { using namespace sw::universal; + std::string test_suite = "areal assignment"; + std::string test_tag = "assignment"; + std::cout << test_suite << '\n'; bool bReportIndividualTestCases = false; int nrOfFailedTestCases = 0; - std::string tag = "AREAL assignment: "; - #if MANUAL_TESTING using Real = sw::universal::areal<8, 2>; @@ -503,7 +501,6 @@ try { nrOfFailedTestCases = 0; // disregard any test failures in manual testing mode #else - std::cout << "AREAL assignment validation\n"; bool bVerbose = false; @@ -514,34 +511,34 @@ try { nrOfFailedTestCases += VerifySpecialCases("long double->areal special cases"); std::cout << "Single block representations\n--------------------------------------------- es = 1 encodings\n"; - nrOfFailedTestCases += TestSingleBlockRepresentations<1, float>(tag, "=float", bReportIndividualTestCases, bVerbose); - nrOfFailedTestCases += TestSingleBlockRepresentations<1, double>(tag, "=double", bReportIndividualTestCases, bVerbose); + nrOfFailedTestCases += TestSingleBlockRepresentations<1, float>(test_tag, "=float", bReportIndividualTestCases, bVerbose); + nrOfFailedTestCases += TestSingleBlockRepresentations<1, double>(test_tag, "=double", bReportIndividualTestCases, bVerbose); std::cout << "--------------------------------------------- es = 2 encodings\n"; - nrOfFailedTestCases += TestSingleBlockRepresentations<2, float>(tag, "=float", bReportIndividualTestCases, bVerbose); - nrOfFailedTestCases += TestSingleBlockRepresentations<2, double>(tag, "=double", bReportIndividualTestCases, bVerbose); + nrOfFailedTestCases += TestSingleBlockRepresentations<2, float>(test_tag, "=float", bReportIndividualTestCases, bVerbose); + nrOfFailedTestCases += TestSingleBlockRepresentations<2, double>(test_tag, "=double", bReportIndividualTestCases, bVerbose); std::cout << "--------------------------------------------- es = 3 encodings\n"; - nrOfFailedTestCases += TestSingleBlockRepresentations<3, float>(tag, "=float", bReportIndividualTestCases, bVerbose); - nrOfFailedTestCases += TestSingleBlockRepresentations<3, double>(tag, "=double", bReportIndividualTestCases, bVerbose); + nrOfFailedTestCases += TestSingleBlockRepresentations<3, float>(test_tag, "=float", bReportIndividualTestCases, bVerbose); + nrOfFailedTestCases += TestSingleBlockRepresentations<3, double>(test_tag, "=double", bReportIndividualTestCases, bVerbose); std::cout << "--------------------------------------------- es = 4 encodings\n"; - nrOfFailedTestCases += TestSingleBlockRepresentations<4, float>(tag, "=float", bReportIndividualTestCases, bVerbose); - nrOfFailedTestCases += TestSingleBlockRepresentations<4, double>(tag, "=double", bReportIndividualTestCases, bVerbose); + nrOfFailedTestCases += TestSingleBlockRepresentations<4, float>(test_tag, "=float", bReportIndividualTestCases, bVerbose); + nrOfFailedTestCases += TestSingleBlockRepresentations<4, double>(test_tag, "=double", bReportIndividualTestCases, bVerbose); std::cout << "Double block representations\n--------------------------------------------- es = 1 encodings\n"; - nrOfFailedTestCases += TestDoubleBlockRepresentations<1, float>(tag, "=float", bReportIndividualTestCases, bVerbose); - nrOfFailedTestCases += TestDoubleBlockRepresentations<1, double>(tag, "=double", bReportIndividualTestCases, bVerbose); + nrOfFailedTestCases += TestDoubleBlockRepresentations<1, float>(test_tag, "=float", bReportIndividualTestCases, bVerbose); + nrOfFailedTestCases += TestDoubleBlockRepresentations<1, double>(test_tag, "=double", bReportIndividualTestCases, bVerbose); std::cout << "--------------------------------------------- es = 2 encodings\n"; - nrOfFailedTestCases += TestDoubleBlockRepresentations<2, float>(tag, "=float", bReportIndividualTestCases, bVerbose); - nrOfFailedTestCases += TestDoubleBlockRepresentations<2, double>(tag, "=double", bReportIndividualTestCases, bVerbose); + nrOfFailedTestCases += TestDoubleBlockRepresentations<2, float>(test_tag, "=float", bReportIndividualTestCases, bVerbose); + nrOfFailedTestCases += TestDoubleBlockRepresentations<2, double>(test_tag, "=double", bReportIndividualTestCases, bVerbose); std::cout << "--------------------------------------------- es = 3 encodings\n"; - nrOfFailedTestCases += TestDoubleBlockRepresentations<3, float>(tag, "=float", bReportIndividualTestCases, bVerbose); - nrOfFailedTestCases += TestDoubleBlockRepresentations<3, double>(tag, "=double", bReportIndividualTestCases, bVerbose); + nrOfFailedTestCases += TestDoubleBlockRepresentations<3, float>(test_tag, "=float", bReportIndividualTestCases, bVerbose); + nrOfFailedTestCases += TestDoubleBlockRepresentations<3, double>(test_tag, "=double", bReportIndividualTestCases, bVerbose); std::cout << "--------------------------------------------- es = 4 encodings\n"; - nrOfFailedTestCases += TestDoubleBlockRepresentations<4, float>(tag, "=float", bReportIndividualTestCases, bVerbose); - nrOfFailedTestCases += TestDoubleBlockRepresentations<4, double>(tag, "=double", bReportIndividualTestCases, bVerbose); + nrOfFailedTestCases += TestDoubleBlockRepresentations<4, float>(test_tag, "=float", bReportIndividualTestCases, bVerbose); + nrOfFailedTestCases += TestDoubleBlockRepresentations<4, double>(test_tag, "=double", bReportIndividualTestCases, bVerbose); std::cout << "Triple block representations\n--------------------------------------------- es = 1 encodings\n"; - nrOfFailedTestCases += TestTripleBlockRepresentations<1, float>(tag, "=float", bReportIndividualTestCases, bVerbose); - nrOfFailedTestCases += TestTripleBlockRepresentations<1, double>(tag, "=double", bReportIndividualTestCases, bVerbose); + nrOfFailedTestCases += TestTripleBlockRepresentations<1, float>(test_tag, "=float", bReportIndividualTestCases, bVerbose); + nrOfFailedTestCases += TestTripleBlockRepresentations<1, double>(test_tag, "=double", bReportIndividualTestCases, bVerbose); /* diff --git a/tests/areal/api/constexpr.cpp b/tests/areal/api/constexpr.cpp index 7ccedb161..01784d160 100644 --- a/tests/areal/api/constexpr.cpp +++ b/tests/areal/api/constexpr.cpp @@ -14,16 +14,11 @@ // second: enable/disable areal arithmetic exceptions #define AREAL_THROW_ARITHMETIC_EXCEPTION 1 -// minimum set of include files to reflect source code dependencies -#include -// fixed-point type manipulators such as pretty printers -#include -#include +#include +#include -#if BIT_CAST_SUPPORT // stylistic constexpr of pi that we'll assign constexpr to an areal constexpr double pi = 3.14159265358979323846; -#endif // BIT_CAST_SUPPORT template void TestConstexprConstruction() { @@ -112,9 +107,9 @@ int main() try { using namespace sw::universal; + std::string test_suite = "areal constexpr "; + std::cout << test_suite << '\n'; int nrOfFailedTestCases = 0; - - std::cout << "AREAL constexpr tests\n"; using Real = areal<12, 2>; Real a; @@ -124,12 +119,7 @@ try { TestConstexprAssignment(); TestConstexprSpecificValues(); - if (nrOfFailedTestCases > 0) { - std::cout << "FAIL\n"; - } - else { - std::cout << "PASS\n"; - } + ReportTestSuiteResults(test_suite, nrOfFailedTestCases); return (nrOfFailedTestCases > 0 ? EXIT_FAILURE : EXIT_SUCCESS); } catch (char const* msg) { diff --git a/tests/areal/api/special_cases.cpp b/tests/areal/api/special_cases.cpp index cb2c899ed..57768c2f7 100644 --- a/tests/areal/api/special_cases.cpp +++ b/tests/areal/api/special_cases.cpp @@ -12,9 +12,8 @@ #include #include #include -// minimum set of include files to reflect source code dependencies -#include -#include // hex_print and the like + +#include #include #include diff --git a/tests/areal/arithmetic/addition.cpp b/tests/areal/arithmetic/addition.cpp index 14b67b0ab..a3f2fe201 100644 --- a/tests/areal/arithmetic/addition.cpp +++ b/tests/areal/arithmetic/addition.cpp @@ -8,8 +8,8 @@ #pragma warning(disable : 4710) // function is not inlined #pragma warning(disable : 5045) // Compiler will insert Spectre mitigation for memory load if /Qspectre switch specified #endif -// minimum set of include files to reflect source code dependencies -#include + +#include #include #include #include diff --git a/tests/areal/conversion/double_conversion.cpp b/tests/areal/conversion/double_conversion.cpp index ba334987b..bbf9134f7 100644 --- a/tests/areal/conversion/double_conversion.cpp +++ b/tests/areal/conversion/double_conversion.cpp @@ -18,10 +18,7 @@ // third: enable trace conversion #define TRACE_CONVERSION 0 -// minimum set of include files to reflect source code dependencies -#include -#include -#include +#include #include #include #include // only used for value table generation diff --git a/tests/areal/conversion/float_conversion.cpp b/tests/areal/conversion/float_conversion.cpp index 5d858c667..9a5027567 100644 --- a/tests/areal/conversion/float_conversion.cpp +++ b/tests/areal/conversion/float_conversion.cpp @@ -18,10 +18,7 @@ // third: enable trace conversion #define TRACE_CONVERSION 0 -// minimum set of include files to reflect source code dependencies -#include -#include -#include +#include #include #include #include // only used for value table generation diff --git a/tests/areal/conversion/sampling.cpp b/tests/areal/conversion/sampling.cpp index 310665a13..304249ee7 100644 --- a/tests/areal/conversion/sampling.cpp +++ b/tests/areal/conversion/sampling.cpp @@ -16,10 +16,7 @@ // second: enable/disable arithmetic exceptions #define AREAL_THROW_ARITHMETIC_EXCEPTION 0 -// minimum set of include files to reflect source code dependencies -#include -#include -#include +#include #include diff --git a/tests/areal/logic/logic.cpp b/tests/areal/logic/logic.cpp index f768767c3..260558136 100644 --- a/tests/areal/logic/logic.cpp +++ b/tests/areal/logic/logic.cpp @@ -4,8 +4,7 @@ // // This file is part of the universal numbers project, which is released under an MIT Open Source license. -// minimum set of include files to reflect source code dependencies -#include +#include #include namespace sw::universal { diff --git a/tests/areal/standard/double_precision.cpp b/tests/areal/standard/double_precision.cpp index 4b6de1c27..6f9ebfc15 100644 --- a/tests/areal/standard/double_precision.cpp +++ b/tests/areal/standard/double_precision.cpp @@ -5,37 +5,15 @@ // This file is part of the universal numbers project, which is released under an MIT Open Source license. #include #include -// minimum set of include files to reflect source code dependencies -#include + +#include #include int main(int argc, char** argv) try { using namespace sw::universal; - //const size_t RND_TEST_CASES = 500000; - - constexpr size_t nbits = 64; - constexpr size_t es = 11; - int nrOfFailedTestCases = 0; - std::string tag = " cfloat<64,11>"; - - std::cout << "Standard double-precision cfloat<64,52> configuration tests\n"; - - cfloat r; - r = 1.2345; - std::cout << r << '\n'; - -#if 0 - std::cout << "Arithmetic tests " << RND_TEST_CASES << " randoms each" << std::endl; - bool bReportIndividualTestCases = false; - - nrOfFailedTestCases += ReportTestResult(ValidateThroughRandoms(tag, bReportIndividualTestCases, OPCODE_ADD, RND_TEST_CASES), tag, "addition "); - nrOfFailedTestCases += ReportTestResult(ValidateThroughRandoms(tag, bReportIndividualTestCases, OPCODE_SUB, RND_TEST_CASES), tag, "subtraction "); - nrOfFailedTestCases += ReportTestResult(ValidateThroughRandoms(tag, bReportIndividualTestCases, OPCODE_MUL, RND_TEST_CASES), tag, "multiplication"); - nrOfFailedTestCases += ReportTestResult(ValidateThroughRandoms(tag, bReportIndividualTestCases, OPCODE_DIV, RND_TEST_CASES), tag, "division "); -#endif return (nrOfFailedTestCases > 0 ? EXIT_FAILURE : EXIT_SUCCESS); } @@ -43,11 +21,11 @@ catch (char const* msg) { std::cerr << "Caught exception: " << msg << std::endl; return EXIT_FAILURE; } -catch (const sw::universal::cfloat_arithmetic_exception& err) { +catch (const sw::universal::areal_arithmetic_exception& err) { std::cerr << "Uncaught real arithmetic exception: " << err.what() << std::endl; return EXIT_FAILURE; } -catch (const sw::universal::cfloat_internal_exception& err) { +catch (const sw::universal::areal_internal_exception& err) { std::cerr << "Uncaught real internal exception: " << err.what() << std::endl; return EXIT_FAILURE; } diff --git a/tests/areal/standard/half_precision.cpp b/tests/areal/standard/half_precision.cpp index e62c01505..adc0af93a 100644 --- a/tests/areal/standard/half_precision.cpp +++ b/tests/areal/standard/half_precision.cpp @@ -5,8 +5,8 @@ // This file is part of the universal numbers project, which is released under an MIT Open Source license. #include #include -// minimum set of include files to reflect source code dependencies -#include + +#include #include // Standard posit with nbits = 16 have es = 1 exponent bit. @@ -15,29 +15,8 @@ int main(int argc, char** argv) try { using namespace sw::universal; - //const size_t RND_TEST_CASES = 500000; - - const size_t nbits = 16; - const size_t es = 5; - int nrOfFailedTestCases = 0; - std::string tag = " cfloat<16,5>"; - - std::cout << "Standard cfloat<16,5> configuration tests\n"; - - cfloat r; - r = 1.2345; - std::cout << r << '\n'; - -#if 0 - cout << "Arithmetic tests " << RND_TEST_CASES << " randoms each" << endl; - bool bReportIndividualTestCases = false; - nrOfFailedTestCases += ReportTestResult(ValidateThroughRandoms(tag, bReportIndividualTestCases, OPCODE_ADD, RND_TEST_CASES), tag, "addition "); - nrOfFailedTestCases += ReportTestResult(ValidateThroughRandoms(tag, bReportIndividualTestCases, OPCODE_SUB, RND_TEST_CASES), tag, "subtraction "); - nrOfFailedTestCases += ReportTestResult(ValidateThroughRandoms(tag, bReportIndividualTestCases, OPCODE_MUL, RND_TEST_CASES), tag, "multiplication"); - nrOfFailedTestCases += ReportTestResult(ValidateThroughRandoms(tag, bReportIndividualTestCases, OPCODE_DIV, RND_TEST_CASES), tag, "division "); -#endif return (nrOfFailedTestCases > 0 ? EXIT_FAILURE : EXIT_SUCCESS); } @@ -45,11 +24,11 @@ catch (char const* msg) { std::cerr << "Caught exception: " << msg << std::endl; return EXIT_FAILURE; } -catch (const sw::universal::cfloat_arithmetic_exception& err) { +catch (const sw::universal::areal_arithmetic_exception& err) { std::cerr << "Uncaught real arithmetic exception: " << err.what() << std::endl; return EXIT_FAILURE; } -catch (const sw::universal::cfloat_internal_exception& err) { +catch (const sw::universal::areal_internal_exception& err) { std::cerr << "Uncaught real internal exception: " << err.what() << std::endl; return EXIT_FAILURE; } diff --git a/tests/areal/standard/quad_precision.cpp b/tests/areal/standard/quad_precision.cpp index 111f94d00..e75df37d3 100644 --- a/tests/areal/standard/quad_precision.cpp +++ b/tests/areal/standard/quad_precision.cpp @@ -5,37 +5,15 @@ // This file is part of the universal numbers project, which is released under an MIT Open Source license. #include #include -// minimum set of include files to reflect source code dependencies -#include + +#include #include int main(int argc, char** argv) try { using namespace sw::universal; - //const size_t RND_TEST_CASES = 500000; - - constexpr size_t nbits = 128; - constexpr size_t es = 15; - int nrOfFailedTestCases = 0; - std::string tag = " areal<128,15>"; - - std::cout << "Standard quad-precision cfloat<128,15> configuration tests\n"; - - cfloat r; - r = 1.2345; - std::cout << r << '\n'; - -#if 0 - std::cout << "Arithmetic tests " << RND_TEST_CASES << " randoms each" << std::endl; - bool bReportIndividualTestCases = false; - - nrOfFailedTestCases += ReportTestResult(ValidateThroughRandoms(tag, bReportIndividualTestCases, OPCODE_ADD, RND_TEST_CASES), tag, "addition "); - nrOfFailedTestCases += ReportTestResult(ValidateThroughRandoms(tag, bReportIndividualTestCases, OPCODE_SUB, RND_TEST_CASES), tag, "subtraction "); - nrOfFailedTestCases += ReportTestResult(ValidateThroughRandoms(tag, bReportIndividualTestCases, OPCODE_MUL, RND_TEST_CASES), tag, "multiplication"); - nrOfFailedTestCases += ReportTestResult(ValidateThroughRandoms(tag, bReportIndividualTestCases, OPCODE_DIV, RND_TEST_CASES), tag, "division "); -#endif return (nrOfFailedTestCases > 0 ? EXIT_FAILURE : EXIT_SUCCESS); } @@ -43,11 +21,11 @@ catch (char const* msg) { std::cerr << "Caught exception: " << msg << std::endl; return EXIT_FAILURE; } -catch (const sw::universal::cfloat_arithmetic_exception& err) { +catch (const sw::universal::areal_arithmetic_exception& err) { std::cerr << "Uncaught real arithmetic exception: " << err.what() << std::endl; return EXIT_FAILURE; } -catch (const sw::universal::cfloat_internal_exception& err) { +catch (const sw::universal::areal_internal_exception& err) { std::cerr << "Uncaught real internal exception: " << err.what() << std::endl; return EXIT_FAILURE; } diff --git a/tests/areal/standard/quarter_precision.cpp b/tests/areal/standard/quarter_precision.cpp index b9da0690f..fb521b5f6 100644 --- a/tests/areal/standard/quarter_precision.cpp +++ b/tests/areal/standard/quarter_precision.cpp @@ -10,10 +10,9 @@ #endif #include #include -// minimum set of include files to reflect source code dependencies -#include -#include -#include + +#include +#include #define MANUAL_TESTING 1 #define STRESS_TESTING 0 @@ -22,41 +21,8 @@ int main(int argc, char** argv) try { using namespace sw::universal; - if (argc > 0) { - std::cout << argv[0] << std::endl; - } - // const size_t RND_TEST_CASES = 0; // no randoms, 8-bit posits can be done exhaustively - - constexpr size_t nbits = 8; - constexpr size_t es = 2; - int nrOfFailedTestCases = 0; - std::string tag = " areal<8,2>"; - - std::cout << "Standard quarter precision cfloat<8,2> configuration tests\n"; - -#if MANUAL_TESTING - - bool bReportIndividualTestCases = true; - { - using TestType = cfloat; - nrOfFailedTestCases += ExhaustiveNumberSystemTest(tag, bReportIndividualTestCases); - } - - -#else // !MANUAL_TESTING - - bool bReportIndividualTestCases = false; - nrOfFailedTestCases += ExhaustiveNumberSystemTest(bReportIndividualTestCases); - -#endif // MANUAL_TESTING - if (nrOfFailedTestCases) { - std::cout << tag << " tests FAIL: " << nrOfFailedTestCases << " failures\n"; - } - else { - std::cout << tag << " tests PASS\n"; - } return (nrOfFailedTestCases > 0 ? EXIT_FAILURE : EXIT_SUCCESS); } catch (char const* msg) { diff --git a/tests/areal/standard/single_precision.cpp b/tests/areal/standard/single_precision.cpp index 78e306fac..942a38d15 100644 --- a/tests/areal/standard/single_precision.cpp +++ b/tests/areal/standard/single_precision.cpp @@ -5,37 +5,15 @@ // This file is part of the universal numbers project, which is released under an MIT Open Source license. #include #include -// minimum set of include files to reflect source code dependencies -#include + +#include #include int main(int argc, char** argv) try { using namespace sw::universal; - //const size_t RND_TEST_CASES = 500000; - - constexpr size_t nbits = 32; - constexpr size_t es = 8; - int nrOfFailedTestCases = 0; - std::string tag = " cfloat<32,8>"; - - std::cout << "Standard single-precision cfloat<8,23> configuration tests\n"; - - cfloat r; - r = 1.2345; - std::cout << r << '\n'; - -#if 0 - std::cout << "Arithmetic tests " << RND_TEST_CASES << " randoms each" << std::endl; - bool bReportIndividualTestCases = false; - - nrOfFailedTestCases += ReportTestResult(ValidateThroughRandoms(tag, bReportIndividualTestCases, OPCODE_ADD, RND_TEST_CASES), tag, "addition "); - nrOfFailedTestCases += ReportTestResult(ValidateThroughRandoms(tag, bReportIndividualTestCases, OPCODE_SUB, RND_TEST_CASES), tag, "subtraction "); - nrOfFailedTestCases += ReportTestResult(ValidateThroughRandoms(tag, bReportIndividualTestCases, OPCODE_MUL, RND_TEST_CASES), tag, "multiplication"); - nrOfFailedTestCases += ReportTestResult(ValidateThroughRandoms(tag, bReportIndividualTestCases, OPCODE_DIV, RND_TEST_CASES), tag, "division "); -#endif return (nrOfFailedTestCases > 0 ? EXIT_FAILURE : EXIT_SUCCESS); } @@ -43,11 +21,11 @@ catch (char const* msg) { std::cerr << "Caught exception: " << msg << std::endl; return EXIT_FAILURE; } -catch (const sw::universal::cfloat_arithmetic_exception& err) { +catch (const sw::universal::areal_arithmetic_exception& err) { std::cerr << "Uncaught real arithmetic exception: " << err.what() << std::endl; return EXIT_FAILURE; } -catch (const sw::universal::cfloat_internal_exception& err) { +catch (const sw::universal::areal_internal_exception& err) { std::cerr << "Uncaught real internal exception: " << err.what() << std::endl; return EXIT_FAILURE; } diff --git a/tests/fixpnt/api/api.cpp b/tests/fixpnt/api/api.cpp index 4f79c1a80..8a7828c24 100644 --- a/tests/fixpnt/api/api.cpp +++ b/tests/fixpnt/api/api.cpp @@ -10,6 +10,7 @@ // second: enable/disable fixpnt arithmetic exceptions #define FIXPNT_THROW_ARITHMETIC_EXCEPTION 1 #include +#include // Regression testing guards: typically set by the cmake configuration, but MANUAL_TESTING is an override #define MANUAL_TESTING 1 @@ -29,9 +30,11 @@ try { if (argc > 0) { std::cout << argv[0] << std::endl; } + std::string test_suite = "fixed-point class interface "; + std::cout << test_suite << '\n'; int nrOfFailedTestCases = 0; - std::cout << "fixed-point class interface tests\n"; + ///////////////////////////////////////////////////////////////////////////////////// //// MODULAR fixed-point (the default) @@ -368,12 +371,7 @@ try { } #endif // LATER - if (nrOfFailedTestCases > 0) { - std::cout << "FAIL\n"; - } - else { - std::cout << "PASS\n"; - } + ReportTestSuiteResults(test_suite, nrOfFailedTestCases); return (nrOfFailedTestCases > 0 ? EXIT_FAILURE : EXIT_SUCCESS); } catch (char const* msg) {