diff --git a/.github/workflows/multiprecision.yml b/.github/workflows/multiprecision.yml index a04c8af3..3cdae907 100644 --- a/.github/workflows/multiprecision.yml +++ b/.github/workflows/multiprecision.yml @@ -139,6 +139,68 @@ jobs: - name: Test run: ../../../b2 -j2 toolset=$TOOLSET ${{ matrix.suite }} define=CI_SUPPRESS_KNOWN_ISSUES working-directory: ../boost-root/libs/multiprecision/test + ubuntu-focal-standalone-tests: + runs-on: ubuntu-20.04 + defaults: + run: + shell: bash + strategy: + fail-fast: false + matrix: + compiler: [ g++-11 ] + standard: [ c++11, c++14, c++17, c++20 ] + suite: [ standalone ] + steps: + - uses: actions/checkout@v2 + with: + fetch-depth: '0' + - name: Set TOOLSET + run: echo ${{ matrix.compiler }} | awk '/^g/ { print "TOOLSET=gcc" } /^clang/ { print "TOOLSET=clang" }' >> $GITHUB_ENV + - name: Add repository + continue-on-error: true + id: addrepo + run: sudo apt-add-repository -y "ppa:ubuntu-toolchain-r/test" + - name: Retry Add Repo + continue-on-error: true + id: retry1 + if: steps.addrepo.outcome=='failure' + run: sudo apt-add-repository -y "ppa:ubuntu-toolchain-r/test" + - name: Retry Add Repo 2 + continue-on-error: true + id: retry2 + if: steps.retry1.outcome=='failure' + run: sudo apt-add-repository -y "ppa:ubuntu-toolchain-r/test" + - name: Install packages + run: sudo apt install g++-11 libgmp-dev libmpfr-dev libtommath-dev + - name: Checkout main boost + run: git clone -b develop --depth 1 https://github.com/boostorg/boost.git ../boost-root + - name: Update tools/boostdep + run: git submodule update --init tools/boostdep + working-directory: ../boost-root + - name: Copy files + run: cp -r $GITHUB_WORKSPACE/* libs/multiprecision + working-directory: ../boost-root + - name: Install deps + run: python tools/boostdep/depinst/depinst.py multiprecision + working-directory: ../boost-root + - name: Bootstrap + run: ./bootstrap.sh + working-directory: ../boost-root + - name: Generate headers + run: ./b2 headers + working-directory: ../boost-root + - name: Generate user config + run: 'echo "using $TOOLSET : : ${{ matrix.compiler }} : -std=${{ matrix.standard }} ;" > ~/user-config.jam' + working-directory: ../boost-root + - name: Config info install + run: ../../../b2 config_info_travis_install toolset=$TOOLSET + working-directory: ../boost-root/libs/config/test + - name: Config info + run: ./config_info_travis + working-directory: ../boost-root/libs/config/test + - name: Test + run: ../../../b2 -j2 toolset=$TOOLSET ${{ matrix.suite }} define=CI_SUPPRESS_KNOWN_ISSUES + working-directory: ../boost-root/libs/multiprecision/test ubuntu-focal-ASAN: runs-on: ubuntu-20.04 defaults: diff --git a/include/boost/multiprecision/cpp_int/misc.hpp b/include/boost/multiprecision/cpp_int/misc.hpp index 77a6f407..cb67d69a 100644 --- a/include/boost/multiprecision/cpp_int/misc.hpp +++ b/include/boost/multiprecision/cpp_int/misc.hpp @@ -1335,7 +1335,7 @@ inline BOOST_CXX14_CONSTEXPR T constexpr_lcm(T a, T b) noexcept #else template -inline BOOST_CXX14_CONSTEXPR constexpr_gcd(T a, T b) noexcept +inline BOOST_CXX14_CONSTEXPR T constexpr_gcd(T a, T b) noexcept { return boost::multiprecision::backends::eval_gcd(a, b); } diff --git a/test/Jamfile.v2 b/test/Jamfile.v2 index fdf9a967..ea8c7af2 100644 --- a/test/Jamfile.v2 +++ b/test/Jamfile.v2 @@ -948,14 +948,6 @@ test-suite misc : [ check-target-builds ../config//has_gmp : : no ] release # otherwise [ runtime is too slow!! ] - - [ run test_miller_rabin_standalone.cpp no_eh_support gmp - : # command line - : # input files - : # requirements - [ check-target-builds ../config//has_gmp : : no ] - release # otherwise [ runtime is too slow!! - ] [ run test_rational_io.cpp $(TOMMATH) no_eh_support : # command line @@ -1169,6 +1161,30 @@ test-suite misc : [ run test_eigen_interop_mpc.cpp mpc mpfr gmp : : : release [ check-target-builds ../config//has_eigen : : no ] [ check-target-builds ../config//has_mpc : : no ] ] ; +test-suite standalone : + + [ run standalone_constexpr_test_cpp_int.cpp : : : [ requires cxx14_constexpr cxx17_if_constexpr ] [ check-target-builds ../config//has_is_constant_evaluated : : no ] ] + [ compile standalone_constexpr_test_float128.cpp : + [ requires cxx14_constexpr cxx17_if_constexpr ] [ check-target-builds ../config//has_float128 : quadmath : no ] ] + + [ run standalone_test_arithmetic_ab.cpp no_eh_support ] + + [ run standalone_test_arithmetic_complex128.cpp : : : [ check-target-builds ../config//has_float128 : quadmath ] ] + [ run standalone_test_arithmetic_cpp_bin_float.cpp no_eh_support : : : msvc:-bigobj ] + [ run standalone_test_arithmetic_cpp_dec_float.cpp no_eh_support : : : msvc:-bigobj ] + [ run standalone_test_arithmetic_cpp_int.cpp no_eh_support : : : msvc:-bigobj ] + [ run standalone_test_arithmetic_int512.cpp no_eh_support : : : msvc:-bigobj ] + [ run standalone_test_arithmetic_cpp_rational.cpp no_eh_support : : : msvc:-bigobj ] + [ run standalone_test_arithmetic_float_128.cpp quadmath no_eh_support : : : [ check-target-builds ../config//has_float128 : : no ] ] + + [ run standalone_test_miller_rabin.cpp no_eh_support gmp + : # command line + : # input files + : # requirements + [ check-target-builds ../config//has_gmp : : no ] + release # otherwise [ runtime is too slow!! + ] +; # # This take too long to run as a regular part of the tests: diff --git a/test/standalone_constexpr_test_cpp_int.cpp b/test/standalone_constexpr_test_cpp_int.cpp new file mode 100644 index 00000000..31575fa7 --- /dev/null +++ b/test/standalone_constexpr_test_cpp_int.cpp @@ -0,0 +1,104 @@ +// (C) Copyright John Maddock 2019 - 2021. +// (C) Copyright Matt Borland 2021. +// Use, modification and distribution are subject to the +// Boost Software License, Version 1.0. (See accompanying file +// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) + +#include "test.hpp" + +#define BOOST_MP_STANDALONE + +#include "constexpr_arithmetric_test.hpp" +#include "boost/multiprecision/cpp_int.hpp" + +#if !defined(BOOST_MP_NO_CONSTEXPR_DETECTION) && !defined(DISABLE_TESTS) + +template +decltype(std::declval()(std::declval())) non_constexpr_invoke(F f, V v) +{ + return f(v); +} + +int main() +{ + typedef boost::multiprecision::int256_t int_backend; + typedef boost::multiprecision::uint256_t unsigned_backend; + + { + constexpr int_backend a(22); + constexpr unsigned_backend c(22); + constexpr int_backend b = test_constexpr_add_subtract(a); + constexpr unsigned_backend d = test_constexpr_add_subtract(c); + + constexpr long long llv = (long long)b; + + static_assert(b == -108); + static_assert(d == 554); + static_assert(llv == -108); + + BOOST_CHECK_EQUAL(b, non_constexpr_invoke(test_constexpr_add_subtract, a)); + BOOST_CHECK_EQUAL(d, non_constexpr_invoke(test_constexpr_add_subtract, c)); + } + { + constexpr int_backend a(22); + constexpr unsigned_backend c(22); + constexpr int_backend b = test_constexpr_mul_divide(a); + constexpr unsigned_backend d = test_constexpr_mul_divide(c); + static_assert(b == 22); + static_assert(d == 22); + + BOOST_CHECK_EQUAL(b, non_constexpr_invoke(test_constexpr_mul_divide, a)); + BOOST_CHECK_EQUAL(d, non_constexpr_invoke(test_constexpr_mul_divide, c)); + } + { + constexpr int_backend a(22); + constexpr unsigned_backend c(22); + constexpr int_backend b = test_constexpr_bitwise(a); + constexpr unsigned_backend d = test_constexpr_bitwise(c); +#ifdef BOOST_HAS_INT128 + static_assert(b == 230); + static_assert(d == 120); +#else + static_assert(b == 210); + static_assert(d == 106); +#endif + + BOOST_CHECK_EQUAL(b, non_constexpr_invoke(test_constexpr_bitwise, a)); + BOOST_CHECK_EQUAL(d, non_constexpr_invoke(test_constexpr_bitwise, c)); + } + { + constexpr int_backend a(22); + constexpr unsigned_backend c(22); + constexpr int_backend b = test_constexpr_logical(a); + constexpr unsigned_backend d = test_constexpr_logical(c); +#ifdef BOOST_HAS_INT128 + //static_assert(b == 95); + //static_assert(d == 95); +#else + static_assert(b == 82); + static_assert(d == 82); +#endif + BOOST_CHECK_EQUAL(b, non_constexpr_invoke(test_constexpr_logical, a)); + BOOST_CHECK_EQUAL(d, non_constexpr_invoke(test_constexpr_logical, c)); + } + { + constexpr int_backend a(22); + constexpr unsigned_backend c(22); + constexpr int_backend b = test_constexpr_compare(a); + constexpr unsigned_backend d = test_constexpr_compare(c); +#ifdef BOOST_HAS_INT128 + static_assert(b == 95); + static_assert(d == 95); +#else + static_assert(b == 95); + static_assert(d == 95); +#endif + BOOST_CHECK_EQUAL(b, non_constexpr_invoke(test_constexpr_compare, a)); + BOOST_CHECK_EQUAL(d, non_constexpr_invoke(test_constexpr_compare, c)); + } + return boost::report_errors(); +} +#else +int main() {} +#endif + diff --git a/test/standalone_constexpr_test_float128.cpp b/test/standalone_constexpr_test_float128.cpp new file mode 100644 index 00000000..23ad64a1 --- /dev/null +++ b/test/standalone_constexpr_test_float128.cpp @@ -0,0 +1,74 @@ +// (C) Copyright John Maddock 2019 - 2021. +// (C) Copyright Matt Borland 2021. +// Use, modification and distribution are subject to the +// Boost Software License, Version 1.0. (See accompanying file +// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) + +#include "constexpr_arithmetric_test.hpp" + +#define BOOST_MP_STANDALONE + +#include +#include + +int main() +{ + using boost::multiprecision::float128; + + { + constexpr float128 a(22); + constexpr float128 b = test_constexpr_add_subtract(a); + + constexpr __float128 f128 = (__float128)b; + static_assert(f128 == -134.0f); + + constexpr int i = (int)b; + static_assert(i == -134); + + constexpr short s = (short)b; + static_assert(s == -134); + } + { + constexpr float128 a(22); + constexpr float128 b = test_constexpr_mul_divide(a); + static_assert((__float128)b == 0); + } + { + constexpr float128 a(22); + constexpr float128 b = test_constexpr_compare(a); + static_assert((__float128)b == 119); + } + { + constexpr float128 a(0); + static_assert(fpclassify(a) == FP_ZERO); + constexpr float128 b(1); + static_assert(fpclassify(b) == FP_NORMAL); + constexpr float128 c(-1); + static_assert(fpclassify(c) == FP_NORMAL); + static_assert(abs(c) >= 0); + static_assert(fabs(c) >= 0); + constexpr float128 d(std::numeric_limits::epsilon()); + static_assert(fpclassify(c) == FP_NORMAL); + constexpr float128 e((std::numeric_limits::min)()); + static_assert(fpclassify(e) == FP_NORMAL); + constexpr float128 f((std::numeric_limits::max)()); + static_assert(fpclassify(f) == FP_NORMAL); + constexpr float128 g(std::numeric_limits::lowest()); + static_assert(fpclassify(g) == FP_NORMAL); + constexpr float128 h(std::numeric_limits::round_error()); + static_assert(fpclassify(h) == FP_NORMAL); + constexpr float128 i(std::numeric_limits::denorm_min()); + static_assert(fpclassify(i) == FP_SUBNORMAL); + constexpr float128 j(-std::numeric_limits::denorm_min()); + static_assert(fpclassify(j) == FP_SUBNORMAL); + constexpr float128 k(std::numeric_limits::infinity()); + static_assert(fpclassify(k) == FP_INFINITE); + static_assert(isinf(k)); + static_assert(!isnan(k)); + constexpr float128 l(-std::numeric_limits::infinity()); + static_assert(fpclassify(l) == FP_INFINITE); + static_assert(isinf(l)); + static_assert(!isnan(l)); + } + std::cout << "Done!" << std::endl; +} diff --git a/test/standalone_test_arithmetic_ab.cpp b/test/standalone_test_arithmetic_ab.cpp new file mode 100644 index 00000000..2e27042d --- /dev/null +++ b/test/standalone_test_arithmetic_ab.cpp @@ -0,0 +1,21 @@ +/////////////////////////////////////////////////////////////// +// Copyright 2012 - 2021 John Maddock. +// Copyright 2021 Matt Borland. Distributed under the Boost +// Software License, Version 1.0. (See accompanying file +// LICENSE_1_0.txt or copy at https://www.boost.org/LICENSE_1_0.txt + +#ifdef _MSC_VER +#define _SCL_SECURE_NO_WARNINGS +#endif + +#include "../performance/arithmetic_backend.hpp" + +#include "test_arithmetic.hpp" + +int main() +{ + test>>(); + test>>(); + test>>(); + return boost::report_errors(); +} diff --git a/test/standalone_test_arithmetic_complex128.cpp b/test/standalone_test_arithmetic_complex128.cpp new file mode 100644 index 00000000..96b38778 --- /dev/null +++ b/test/standalone_test_arithmetic_complex128.cpp @@ -0,0 +1,23 @@ +/////////////////////////////////////////////////////////////// +// Copyright 2012-2021 John Maddock. +// Copyright 2021 Matt Borland. Distributed under the Boost +// Software License, Version 1.0. (See accompanying file +// LICENSE_1_0.txt or copy at https://www.boost.org/LICENSE_1_0.txt + +#include + +#define BOOST_MP_STANDALONE + +#ifdef BOOST_HAS_FLOAT128 +#include +#endif + +#include "libs/multiprecision/test/test_arithmetic.hpp" + +int main() +{ +#ifdef BOOST_HAS_FLOAT128 + test(); +#endif + return boost::report_errors(); +} diff --git a/test/standalone_test_arithmetic_cpp_bin_float.cpp b/test/standalone_test_arithmetic_cpp_bin_float.cpp new file mode 100644 index 00000000..f79aee9b --- /dev/null +++ b/test/standalone_test_arithmetic_cpp_bin_float.cpp @@ -0,0 +1,27 @@ +/////////////////////////////////////////////////////////////// +// Copyright 2012 - 2021 John Maddock. +// Copyright 2021 Matt Borland. Distributed under the Boost +// Software License, Version 1.0. (See accompanying file +// LICENSE_1_0.txt or copy at https://www.boost.org/LICENSE_1_0.txt + +#include "libs/multiprecision/test/test_arithmetic.hpp" + +#define BOOST_MP_STANDALONE + +#include + +template +struct related_type, ET> > +{ + using number_type = boost::multiprecision::number, ET>; + using type = boost::multiprecision::number::digits / 2) > std::numeric_limits::digits ? Digits / 2 : Digits), DigitBase, Allocator, Exponent, MinExponent, MaxExponent>, ET>; +}; + +int main() +{ + test(); + //test>>(); + //test>>>(); + //test(); + return boost::report_errors(); +} diff --git a/test/standalone_test_arithmetic_cpp_dec_float.cpp b/test/standalone_test_arithmetic_cpp_dec_float.cpp new file mode 100644 index 00000000..8c482230 --- /dev/null +++ b/test/standalone_test_arithmetic_cpp_dec_float.cpp @@ -0,0 +1,23 @@ +/////////////////////////////////////////////////////////////// +// Copyright 2012 - 2021 John Maddock. +// Copyright 2021 Matt Borland. Distributed under the Boost +// Software License, Version 1.0. (See accompanying file +// LICENSE_1_0.txt or copy at https://www.boost.org/LICENSE_1_0.txt + +#include "test_arithmetic.hpp" + +#define BOOST_MP_STANDALONE + +#include + +template +struct related_type>> +{ + using type = boost::multiprecision::number>; +}; + +int main() +{ + test(); + return boost::report_errors(); +} diff --git a/test/standalone_test_arithmetic_cpp_int.cpp b/test/standalone_test_arithmetic_cpp_int.cpp new file mode 100644 index 00000000..8a832879 --- /dev/null +++ b/test/standalone_test_arithmetic_cpp_int.cpp @@ -0,0 +1,32 @@ +/////////////////////////////////////////////////////////////// +// Copyright 2012 - 2021 John Maddock. +// Copyright 2021 Matt Borland. Distributed under the Boost +// Software License, Version 1.0. (See accompanying file +// LICENSE_1_0.txt or copy at https://www.boost.org/LICENSE_1_0.txt + +#include "test_arithmetic.hpp" + +#define BOOST_MP_STANDALONE + +#include + +template +struct is_twos_complement_integer, ExpressionTemplates> > : public std::integral_constant +{}; + +template <> +struct related_type +{ + using type = boost::multiprecision::int256_t; +}; +template +struct related_type, ET> > +{ + using type = boost::multiprecision::number, ET>; +}; + +int main() +{ + test(); + return boost::report_errors(); +} diff --git a/test/standalone_test_arithmetic_cpp_rational.cpp b/test/standalone_test_arithmetic_cpp_rational.cpp new file mode 100644 index 00000000..ae7f56a9 --- /dev/null +++ b/test/standalone_test_arithmetic_cpp_rational.cpp @@ -0,0 +1,37 @@ +/////////////////////////////////////////////////////////////// +// Copyright 2012 - 2021 John Maddock. +// Copyright 2021 Matt Borland. Distributed under the Boost +// Software License, Version 1.0. (See accompanying file +// LICENSE_1_0.txt or copy at https://www.boost.org/LICENSE_1_0.txt + +#include "test_arithmetic.hpp" + +#define BOOST_MP_STANDALONE + +#include + +template +struct is_twos_complement_integer, ExpressionTemplates> > : public std::integral_constant +{}; + +template <> +struct related_type +{ + using type = boost::multiprecision::int256_t; +}; +template <> +struct related_type +{ + using type = boost::multiprecision::cpp_int; +}; +template +struct related_type, ET> > +{ + using type = boost::multiprecision::number, ET>; +}; + +int main() +{ + test(); + return boost::report_errors(); +} diff --git a/test/standalone_test_arithmetic_float_128.cpp b/test/standalone_test_arithmetic_float_128.cpp new file mode 100644 index 00000000..47c6def6 --- /dev/null +++ b/test/standalone_test_arithmetic_float_128.cpp @@ -0,0 +1,21 @@ +/////////////////////////////////////////////////////////////// +// Copyright 2012 - 2021 John Maddock. +// Copyright 2021 Matt Borland. Distributed under the Boost +// Software License, Version 1.0. (See accompanying file +// LICENSE_1_0.txt or copy at https://www.boost.org/LICENSE_1_0.txt + +#ifdef _MSC_VER +#define _SCL_SECURE_NO_WARNINGS +#endif + +#include "test_arithmetic.hpp" + +#define BOOST_MP_STANDALONE + +#include + +int main() +{ + test(); + return boost::report_errors(); +} diff --git a/test/standalone_test_arithmetic_int512.cpp b/test/standalone_test_arithmetic_int512.cpp new file mode 100644 index 00000000..1c4fba82 --- /dev/null +++ b/test/standalone_test_arithmetic_int512.cpp @@ -0,0 +1,32 @@ +/////////////////////////////////////////////////////////////// +// Copyright 2012 - 2021 John Maddock. +// Copyright 2021 Matt Borland. Distributed under the Boost +// Software License, Version 1.0. (See accompanying file +// LICENSE_1_0.txt or copy at https://www.boost.org/LICENSE_1_0.txt + +#include "test_arithmetic.hpp" + +#define BOOST_MP_STANDALONE + +#include + +template +struct is_twos_complement_integer, ExpressionTemplates> > : public std::integral_constant +{}; + +template <> +struct related_type +{ + using type = boost::multiprecision::int256_t; +}; +template +struct related_type, ET> > +{ + using type = boost::multiprecision::number, ET>; +}; + +int main() +{ + test(); + return boost::report_errors(); +} diff --git a/test/test_miller_rabin_standalone.cpp b/test/standalone_test_miller_rabin.cpp similarity index 100% rename from test/test_miller_rabin_standalone.cpp rename to test/standalone_test_miller_rabin.cpp