From 150cbb8f9bcc2f16eac5ccb8831b4606d6ba8758 Mon Sep 17 00:00:00 2001 From: Matt Borland Date: Tue, 23 Mar 2021 19:03:47 +0300 Subject: [PATCH 1/7] Make is_complex less ambiguous --- include/boost/math/tools/complex.hpp | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/include/boost/math/tools/complex.hpp b/include/boost/math/tools/complex.hpp index fc2d817cd..d462ca809 100644 --- a/include/boost/math/tools/complex.hpp +++ b/include/boost/math/tools/complex.hpp @@ -17,18 +17,24 @@ namespace boost { namespace math { namespace tools { + namespace detail { template - struct is_complex_type + struct is_complex_type_impl { static constexpr bool value = false; }; template - struct is_complex_type().real()), - decltype(std::declval().imag())>> + struct is_complex_type_impl().real()), + decltype(std::declval().imag())>> { static constexpr bool value = true; }; + } // Namespace detail + + template + struct is_complex_type : public detail::is_complex_type_impl {}; + // // Use this trait to typecast integer literals to something // that will interoperate with T: From 012607ea745166bb992ab405a2579ae68781e201 Mon Sep 17 00:00:00 2001 From: Matt Borland Date: Tue, 23 Mar 2021 20:04:48 +0300 Subject: [PATCH 2/7] Remove boost.throw_exception dependency (#577) * Remove boost.throw_exception dependency * Remove test #define [ci skip] * Fix missing header in sf_prime_incl_test --- doc/overview/error_handling.qbk | 4 ++++ .../boost/math/cstdfloat/cstdfloat_cmath.hpp | 4 ++-- .../math/cstdfloat/cstdfloat_iostream.hpp | 12 +++++------ .../boost/math/policies/error_handling.hpp | 18 ++++++++--------- .../nonfinite_num_facets.hpp | 9 +++------ .../boost/math/special_functions/owens_t.hpp | 6 +++--- include/boost/math/tools/throw_exception.hpp | 20 +++++++++++++++++++ test/compile_test/sf_prime_incl_test.cpp | 7 ++++--- 8 files changed, 51 insertions(+), 29 deletions(-) create mode 100644 include/boost/math/tools/throw_exception.hpp diff --git a/doc/overview/error_handling.qbk b/doc/overview/error_handling.qbk index 14bc1627e..922a80e0c 100644 --- a/doc/overview/error_handling.qbk +++ b/doc/overview/error_handling.qbk @@ -12,6 +12,10 @@ Handling of errors by this library is split into two orthogonal parts: [warning The default error actions are to throw an exception with an informative error message. [role red If you do not try to catch the exception, you will not see the message!]] +The default behavior is for exceptions to be thrown using boost::throw_exception. +This facility has special handling for exception free environments. +If BOOST_MATH_STANDALONE is defined standard library facilities (e.g. throw) are used for exception handling. + The kinds of errors that can be raised are: [variablelist diff --git a/include/boost/math/cstdfloat/cstdfloat_cmath.hpp b/include/boost/math/cstdfloat/cstdfloat_cmath.hpp index eea3328cc..b71bbd828 100644 --- a/include/boost/math/cstdfloat/cstdfloat_cmath.hpp +++ b/include/boost/math/cstdfloat/cstdfloat_cmath.hpp @@ -24,7 +24,7 @@ #include #include #include -#include +#include #if defined(_WIN32) && defined(__GNUC__) // Several versions of Mingw and probably cygwin too have broken @@ -988,7 +988,7 @@ namespace std v = quadmath_snprintf(&buf2[0], v_max + 3, format.c_str(), digits, m_value); if (v >= v_max + 3) { - BOOST_THROW_EXCEPTION(std::runtime_error("Formatting of float128_type failed.")); + BOOST_MATH_THROW_EXCEPTION(std::runtime_error("Formatting of float128_type failed.")); } s = &buf2[0]; } diff --git a/include/boost/math/cstdfloat/cstdfloat_iostream.hpp b/include/boost/math/cstdfloat/cstdfloat_iostream.hpp index 93dc0c2da..e05b3b86f 100644 --- a/include/boost/math/cstdfloat/cstdfloat_iostream.hpp +++ b/include/boost/math/cstdfloat/cstdfloat_iostream.hpp @@ -29,7 +29,7 @@ #include #include #include - #include + #include // #if (0) #if defined(__GNUC__) @@ -86,7 +86,7 @@ my_digits, x); - if(v < 0) { BOOST_THROW_EXCEPTION(std::runtime_error("Formatting of boost::float128_t failed internally in quadmath_snprintf().")); } + if(v < 0) { BOOST_MATH_THROW_EXCEPTION(std::runtime_error("Formatting of boost::float128_t failed internally in quadmath_snprintf().")); } if(v >= static_cast(sizeof(my_buffer) - 1U)) { @@ -106,7 +106,7 @@ } catch(const std::bad_alloc&) { - BOOST_THROW_EXCEPTION(std::runtime_error("Formatting of boost::float128_t failed while allocating memory.")); + BOOST_MATH_THROW_EXCEPTION(std::runtime_error("Formatting of boost::float128_t failed while allocating memory.")); } #endif const int v2 = ::quadmath_snprintf(my_buffer2, @@ -117,7 +117,7 @@ if(v2 >= v + 3) { - BOOST_THROW_EXCEPTION(std::runtime_error("Formatting of boost::float128_t failed.")); + BOOST_MATH_THROW_EXCEPTION(std::runtime_error("Formatting of boost::float128_t failed.")); } static_cast(ostr << my_buffer2); @@ -152,7 +152,7 @@ is.setstate(ios_base::failbit); - BOOST_THROW_EXCEPTION(std::runtime_error("Unable to interpret input string as a boost::float128_t")); + BOOST_MATH_THROW_EXCEPTION(std::runtime_error("Unable to interpret input string as a boost::float128_t")); } return is; @@ -760,7 +760,7 @@ is.setstate(ios_base::failbit); - BOOST_THROW_EXCEPTION(std::runtime_error("Unable to interpret input string as a boost::float128_t")); + BOOST_MATH_THROW_EXCEPTION(std::runtime_error("Unable to interpret input string as a boost::float128_t")); } return is; diff --git a/include/boost/math/policies/error_handling.hpp b/include/boost/math/policies/error_handling.hpp index 45941e3d1..9b8ac8e9b 100644 --- a/include/boost/math/policies/error_handling.hpp +++ b/include/boost/math/policies/error_handling.hpp @@ -8,20 +8,20 @@ #ifndef BOOST_MATH_POLICY_ERROR_HANDLING_HPP #define BOOST_MATH_POLICY_ERROR_HANDLING_HPP -#include #include #include #include #include #include -#include -#include +#include +#include +#include #include #include #include #include -#include -#include +#include + #ifdef BOOST_MSVC # pragma warning(push) // Quiet warnings in boost/format.hpp # pragma warning(disable: 4996) // _SCL_SECURE_NO_DEPRECATE @@ -140,7 +140,7 @@ void raise_error(const char* pfunction, const char* message) msg += message; E e(msg); - boost::throw_exception(e); + BOOST_MATH_THROW_EXCEPTION(e) } template @@ -167,7 +167,7 @@ void raise_error(const char* pfunction, const char* pmessage, const T& val) msg += message; E e(msg); - boost::throw_exception(e); + BOOST_MATH_THROW_EXCEPTION(e) } template @@ -804,7 +804,7 @@ inline R checked_narrowing_cast(T val, const char* function) BOOST_NOEXCEPT_IF(B } template -inline void check_series_iterations(const char* function, boost::uintmax_t max_iter, const Policy& pol) BOOST_NOEXCEPT_IF(BOOST_MATH_IS_FLOAT(T) && is_noexcept_error_policy::value) +inline void check_series_iterations(const char* function, std::uintmax_t max_iter, const Policy& pol) BOOST_NOEXCEPT_IF(BOOST_MATH_IS_FLOAT(T) && is_noexcept_error_policy::value) { if(max_iter >= policies::get_max_series_iterations()) raise_evaluation_error( @@ -813,7 +813,7 @@ inline void check_series_iterations(const char* function, boost::uintmax_t max_i } template -inline void check_root_iterations(const char* function, boost::uintmax_t max_iter, const Policy& pol) BOOST_NOEXCEPT_IF(BOOST_MATH_IS_FLOAT(T) && is_noexcept_error_policy::value) +inline void check_root_iterations(const char* function, std::uintmax_t max_iter, const Policy& pol) BOOST_NOEXCEPT_IF(BOOST_MATH_IS_FLOAT(T) && is_noexcept_error_policy::value) { if(max_iter >= policies::get_max_root_iterations()) raise_evaluation_error( diff --git a/include/boost/math/special_functions/nonfinite_num_facets.hpp b/include/boost/math/special_functions/nonfinite_num_facets.hpp index cd1eba932..03af4216f 100644 --- a/include/boost/math/special_functions/nonfinite_num_facets.hpp +++ b/include/boost/math/special_functions/nonfinite_num_facets.hpp @@ -22,10 +22,7 @@ #include #include #include - -#include -#include - +#include #include #include @@ -104,7 +101,7 @@ namespace boost { case FP_INFINITE: if(flags_ & trap_infinity) { - BOOST_THROW_EXCEPTION(std::ios_base::failure("Infinity")); + BOOST_MATH_THROW_EXCEPTION(std::ios_base::failure("Infinity")); } else if((boost::math::signbit)(val)) { // negative infinity. @@ -123,7 +120,7 @@ namespace boost { case FP_NAN: if(flags_ & trap_nan) { - BOOST_THROW_EXCEPTION(std::ios_base::failure("NaN")); + BOOST_MATH_THROW_EXCEPTION(std::ios_base::failure("NaN")); } else if((boost::math::signbit)(val)) { // negative so "-nan". diff --git a/include/boost/math/special_functions/owens_t.hpp b/include/boost/math/special_functions/owens_t.hpp index e8e9343a6..1f2e270ac 100644 --- a/include/boost/math/special_functions/owens_t.hpp +++ b/include/boost/math/special_functions/owens_t.hpp @@ -17,15 +17,15 @@ #endif #include -#include #include #include -#include +#include #include #include #include #include +#include #ifdef BOOST_MSVC #pragma warning(push) @@ -829,7 +829,7 @@ namespace boost val = owens_t_T6(h,a, pol); break; default: - BOOST_THROW_EXCEPTION(std::logic_error("selection routine in Owen's T function failed")); + BOOST_MATH_THROW_EXCEPTION(std::logic_error("selection routine in Owen's T function failed")); } return val; } diff --git a/include/boost/math/tools/throw_exception.hpp b/include/boost/math/tools/throw_exception.hpp new file mode 100644 index 000000000..a1d2cda90 --- /dev/null +++ b/include/boost/math/tools/throw_exception.hpp @@ -0,0 +1,20 @@ +// (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) + +#ifndef BOOST_MATH_TOOLS_THROW_EXCEPTION_HPP +#define BOOST_MATH_TOOLS_THROW_EXCEPTION_HPP + +#ifndef BOOST_MATH_STANDALONE + +#include +#define BOOST_MATH_THROW_EXCEPTION(expr) boost::throw_exception(expr); + +#else // Standalone mode - use standard library facilities + +#define BOOST_MATH_THROW_EXCEPTION(expr) throw expr; + +#endif // BOOST_MATH_STANDALONE + +#endif // BOOST_MATH_TOOLS_THROW_EXCEPTION_HPP diff --git a/test/compile_test/sf_prime_incl_test.cpp b/test/compile_test/sf_prime_incl_test.cpp index 6ab758479..647a40624 100644 --- a/test/compile_test/sf_prime_incl_test.cpp +++ b/test/compile_test/sf_prime_incl_test.cpp @@ -12,17 +12,18 @@ // important if this test is to be meaningful: // #include "test_compile_result.hpp" +#include void compile_and_link_test() { - check_result(boost::math::prime(u)); + check_result(boost::math::prime(u)); // // Add constexpr tests here: // #ifdef BOOST_MATH_HAVE_CONSTEXPR_TABLES - constexpr boost::uint32_t ce_f = boost::math::prime(boost::math::max_prime); + constexpr std::uint32_t ce_f = boost::math::prime(boost::math::max_prime); static_assert(ce_f == 104729, "max_prime had incorrect value"); - check_result(ce_f); + check_result(ce_f); #endif } From 4eb6ba6580f957cfc75f9b95e12fa512f9f2b976 Mon Sep 17 00:00:00 2001 From: Matt Borland Date: Tue, 23 Mar 2021 20:05:40 +0300 Subject: [PATCH 3/7] Widen gini coefficient test tolerance (#579) --- test/univariate_statistics_test.cpp | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/test/univariate_statistics_test.cpp b/test/univariate_statistics_test.cpp index 178bd48f2..68cfc7162 100644 --- a/test/univariate_statistics_test.cpp +++ b/test/univariate_statistics_test.cpp @@ -620,7 +620,7 @@ void test_median_absolute_deviation(ExecutionPolicy&& exec) template void test_sample_gini_coefficient(ExecutionPolicy&& exec) { - Real tol = std::numeric_limits::epsilon(); + Real tol = 10*std::numeric_limits::epsilon(); std::vector v{1,0,0}; Real gini = boost::math::statistics::sample_gini_coefficient(exec, v.begin(), v.end()); BOOST_TEST(abs(gini - 1) < tol); @@ -649,7 +649,7 @@ void test_sample_gini_coefficient(ExecutionPolicy&& exec) template void test_gini_coefficient(ExecutionPolicy&& exec) { - Real tol = std::numeric_limits::epsilon(); + Real tol = 10*std::numeric_limits::epsilon(); std::vector v{1,0,0}; Real gini = boost::math::statistics::gini_coefficient(exec, v.begin(), v.end()); Real expected = Real(2)/Real(3); @@ -691,8 +691,7 @@ void test_gini_coefficient(ExecutionPolicy&& exec) v[i] = dis(gen); } gini = boost::math::statistics::gini_coefficient(exec, v); - BOOST_TEST(abs(gini - expected) < 0.02); - + BOOST_TEST(abs(gini - expected) < Real(0.03)); } template From d5a69c3a318c73da46cb2f42ff2fa18491c720b6 Mon Sep 17 00:00:00 2001 From: Matt Borland Date: Wed, 24 Mar 2021 18:45:17 +0300 Subject: [PATCH 4/7] Fix for beta link error --- include/boost/math/special_functions/acosh.hpp | 1 + include/boost/math/special_functions/asinh.hpp | 1 + include/boost/math/special_functions/atanh.hpp | 1 + include/boost/math/special_functions/log1p.hpp | 1 + 4 files changed, 4 insertions(+) diff --git a/include/boost/math/special_functions/acosh.hpp b/include/boost/math/special_functions/acosh.hpp index cdc490559..9db69ec91 100644 --- a/include/boost/math/special_functions/acosh.hpp +++ b/include/boost/math/special_functions/acosh.hpp @@ -22,6 +22,7 @@ #include #include #include +#include // This is the inverse of the hyperbolic cosine function. diff --git a/include/boost/math/special_functions/asinh.hpp b/include/boost/math/special_functions/asinh.hpp index e55a35628..3dc1f63f4 100644 --- a/include/boost/math/special_functions/asinh.hpp +++ b/include/boost/math/special_functions/asinh.hpp @@ -23,6 +23,7 @@ #include #include #include +#include // This is the inverse of the hyperbolic sine function. diff --git a/include/boost/math/special_functions/atanh.hpp b/include/boost/math/special_functions/atanh.hpp index 871a465a8..c2d548dd3 100644 --- a/include/boost/math/special_functions/atanh.hpp +++ b/include/boost/math/special_functions/atanh.hpp @@ -22,6 +22,7 @@ #include #include #include +#include // This is the inverse of the hyperbolic tangent function. diff --git a/include/boost/math/special_functions/log1p.hpp b/include/boost/math/special_functions/log1p.hpp index 7126cc819..44b1844e7 100644 --- a/include/boost/math/special_functions/log1p.hpp +++ b/include/boost/math/special_functions/log1p.hpp @@ -21,6 +21,7 @@ #include #include #include +#include #ifndef BOOST_NO_LIMITS_COMPILE_TIME_CONSTANTS # include From 1ead5e5739bb73ddc0760f6f3f52515384477e69 Mon Sep 17 00:00:00 2001 From: jzmaddock Date: Wed, 24 Mar 2021 20:19:16 +0000 Subject: [PATCH 5/7] Add missing #include tests for acosh, asinh and atanh. --- test/Jamfile.v2 | 3 +++ test/compile_test/sf_acosh_incl_test.cpp | 23 +++++++++++++++++++++++ test/compile_test/sf_asinh_incl_test.cpp | 23 +++++++++++++++++++++++ test/compile_test/sf_atanh_incl_test.cpp | 23 +++++++++++++++++++++++ 4 files changed, 72 insertions(+) create mode 100644 test/compile_test/sf_acosh_incl_test.cpp create mode 100644 test/compile_test/sf_asinh_incl_test.cpp create mode 100644 test/compile_test/sf_atanh_incl_test.cpp diff --git a/test/Jamfile.v2 b/test/Jamfile.v2 index caf191713..da3667aa1 100644 --- a/test/Jamfile.v2 +++ b/test/Jamfile.v2 @@ -984,6 +984,9 @@ test-suite misc : [ run compile_test/compl_asinh_incl_test.cpp compile_test_main ] [ run compile_test/compl_atan_incl_test.cpp compile_test_main ] [ run compile_test/compl_atanh_incl_test.cpp compile_test_main ] + [ run compile_test/sf_acosh_incl_test.cpp compile_test_main ] + [ run compile_test/sf_asinh_incl_test.cpp compile_test_main ] + [ run compile_test/sf_atanh_incl_test.cpp compile_test_main ] [ run compile_test/sf_beta_incl_test.cpp compile_test_main ] [ run compile_test/sf_bernoulli_incl_test.cpp compile_test_main ] [ run compile_test/sf_bessel_incl_test.cpp compile_test_main ] diff --git a/test/compile_test/sf_acosh_incl_test.cpp b/test/compile_test/sf_acosh_incl_test.cpp new file mode 100644 index 000000000..2f500a7c9 --- /dev/null +++ b/test/compile_test/sf_acosh_incl_test.cpp @@ -0,0 +1,23 @@ +// Copyright John Maddock 2006. +// 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) +// +// Basic sanity check that header +// #includes all the files that it needs to. +// +#include +// +// Note this header includes no other headers, this is +// important if this test is to be meaningful: +// +#include "test_compile_result.hpp" + +void compile_and_link_test() +{ + check_result(boost::math::acosh(f)); + check_result(boost::math::acosh(d)); +#ifndef BOOST_MATH_NO_LONG_DOUBLE_MATH_FUNCTIONS + check_result(boost::math::acosh(l)); +#endif +} diff --git a/test/compile_test/sf_asinh_incl_test.cpp b/test/compile_test/sf_asinh_incl_test.cpp new file mode 100644 index 000000000..f1b5d40dd --- /dev/null +++ b/test/compile_test/sf_asinh_incl_test.cpp @@ -0,0 +1,23 @@ +// Copyright John Maddock 2006. +// 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) +// +// Basic sanity check that header +// #includes all the files that it needs to. +// +#include +// +// Note this header includes no other headers, this is +// important if this test is to be meaningful: +// +#include "test_compile_result.hpp" + +void compile_and_link_test() +{ + check_result(boost::math::asinh(f)); + check_result(boost::math::asinh(d)); +#ifndef BOOST_MATH_NO_LONG_DOUBLE_MATH_FUNCTIONS + check_result(boost::math::asinh(l)); +#endif +} diff --git a/test/compile_test/sf_atanh_incl_test.cpp b/test/compile_test/sf_atanh_incl_test.cpp new file mode 100644 index 000000000..1040cb939 --- /dev/null +++ b/test/compile_test/sf_atanh_incl_test.cpp @@ -0,0 +1,23 @@ +// Copyright John Maddock 2006. +// 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) +// +// Basic sanity check that header +// #includes all the files that it needs to. +// +#include +// +// Note this header includes no other headers, this is +// important if this test is to be meaningful: +// +#include "test_compile_result.hpp" + +void compile_and_link_test() +{ + check_result(boost::math::atanh(f)); + check_result(boost::math::atanh(d)); +#ifndef BOOST_MATH_NO_LONG_DOUBLE_MATH_FUNCTIONS + check_result(boost::math::atanh(l)); +#endif +} From 7c9fa279f4b6649785aa9487c802cad2d4ce24e7 Mon Sep 17 00:00:00 2001 From: Matt Borland Date: Sun, 21 Mar 2021 10:05:56 +0300 Subject: [PATCH 6/7] Remove boost.predef dependency --- .../special_functions/detail/fp_traits.hpp | 118 ++++++++++-------- include/boost/math/tools/config.hpp | 1 - 2 files changed, 69 insertions(+), 50 deletions(-) diff --git a/include/boost/math/special_functions/detail/fp_traits.hpp b/include/boost/math/special_functions/detail/fp_traits.hpp index 3a69492c1..2eb67215a 100644 --- a/include/boost/math/special_functions/detail/fp_traits.hpp +++ b/include/boost/math/special_functions/detail/fp_traits.hpp @@ -25,8 +25,28 @@ With these techniques, the code could be simplified. #include #include #include + +// Determine endinaness +#ifndef BOOST_MATH_STANDALONE + #include -#include +#define BOOST_MATH_ENDIAN_BIG_BYTE BOOST_ENDIAN_BIG_BYTE +#define BOOST_MATH_ENDIAN_LITTLE_BYTE BOOST_ENDIAN_LITTLE_BYTE + +#else // Using standalone mode +#if (__cplusplus > 202000L || _MSVC_LANG > 202000L) && __has_include() + +#include +#define BOOST_MATH_ENDIAN_BIG_BYTE (std::endian::native == std::endian::big) +#define BOOST_MATH_ENDIAN_LITTLE_BYTE (std::endian::native == std::endian::little) + +#else // Does not have compliant C++20 + +#define BOOST_MATH_ENDIAN_BIG_BYTE (__BYTE_ORDER__ == __ORDER_BIG_ENDIAN__) +#define BOOST_MATH_ENDIAN_LITTLE_BYTE (__BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__) + +#endif // Standalone mode +#endif // Endian #ifdef BOOST_NO_STDC_NAMESPACE namespace std{ using ::memcpy; } @@ -178,10 +198,10 @@ template<> struct fp_traits_non_native { typedef ieee_copy_all_bits_tag method; - BOOST_STATIC_CONSTANT(uint32_t, sign = 0x80000000u); - BOOST_STATIC_CONSTANT(uint32_t, exponent = 0x7f800000); - BOOST_STATIC_CONSTANT(uint32_t, flag = 0x00000000); - BOOST_STATIC_CONSTANT(uint32_t, significand = 0x007fffff); + static constexpr uint32_t sign = 0x80000000u; + static constexpr uint32_t exponent = 0x7f800000; + static constexpr uint32_t flag = 0x00000000; + static constexpr uint32_t significand = 0x007fffff; typedef uint32_t bits; static void get_bits(float x, uint32_t& a) { std::memcpy(&a, &x, 4); } @@ -197,10 +217,10 @@ template<> struct fp_traits_non_native { typedef ieee_copy_leading_bits_tag method; - BOOST_STATIC_CONSTANT(uint32_t, sign = 0x80000000u); - BOOST_STATIC_CONSTANT(uint32_t, exponent = 0x7ff00000); - BOOST_STATIC_CONSTANT(uint32_t, flag = 0); - BOOST_STATIC_CONSTANT(uint32_t, significand = 0x000fffff); + static constexpr uint32_t sign = 0x80000000u; + static constexpr uint32_t exponent = 0x7ff00000; + static constexpr uint32_t flag = 0; + static constexpr uint32_t significand = 0x000fffff; typedef uint32_t bits; @@ -216,10 +236,10 @@ template<> struct fp_traits_non_native private: -#if BOOST_ENDIAN_BIG_BYTE - BOOST_STATIC_CONSTANT(int, offset_ = 0); -#elif BOOST_ENDIAN_LITTLE_BYTE - BOOST_STATIC_CONSTANT(int, offset_ = 4); +#if BOOST_MATH_ENDIAN_BIG_BYTE + static constexpr int offset_ = 0; +#elif BOOST_MATH_ENDIAN_LITTLE_BYTE + static constexpr int offset_ = 4; #else static_assert(false, "Endian type could not be identified"); #endif @@ -233,10 +253,10 @@ template<> struct fp_traits_non_native { typedef ieee_copy_all_bits_tag method; - static const uint64_t sign = ((uint64_t)0x80000000u) << 32; - static const uint64_t exponent = ((uint64_t)0x7ff00000) << 32; - static const uint64_t flag = 0; - static const uint64_t significand + static constexpr uint64_t sign = ((uint64_t)0x80000000u) << 32; + static constexpr uint64_t exponent = ((uint64_t)0x7ff00000) << 32; + static constexpr uint64_t flag = 0; + static constexpr uint64_t significand = (((uint64_t)0x000fffff) << 32) + ((uint64_t)0xffffffffu); typedef uint64_t bits; @@ -257,10 +277,10 @@ template<> struct fp_traits_non_native { typedef ieee_copy_leading_bits_tag method; - BOOST_STATIC_CONSTANT(uint32_t, sign = 0x80000000u); - BOOST_STATIC_CONSTANT(uint32_t, exponent = 0x7ff00000); - BOOST_STATIC_CONSTANT(uint32_t, flag = 0); - BOOST_STATIC_CONSTANT(uint32_t, significand = 0x000fffff); + static constexpr uint32_t sign = 0x80000000u; + static constexpr uint32_t exponent = 0x7ff00000; + static constexpr uint32_t flag = 0; + static constexpr uint32_t significand = 0x000fffff; typedef uint32_t bits; @@ -276,10 +296,10 @@ template<> struct fp_traits_non_native private: -#if BOOST_ENDIAN_BIG_BYTE - BOOST_STATIC_CONSTANT(int, offset_ = 0); -#elif BOOST_ENDIAN_LITTLE_BYTE - BOOST_STATIC_CONSTANT(int, offset_ = 4); +#if BOOST_MATH_ENDIAN_BIG_BYTE + static constexpr int offset_ = 0; +#elif BOOST_MATH_ENDIAN_LITTLE_BYTE + static constexpr int offset_ = 4; #else static_assert(false, "Endian type could not be identified"); #endif @@ -320,10 +340,10 @@ struct fp_traits_non_native { typedef ieee_copy_leading_bits_tag method; - BOOST_STATIC_CONSTANT(uint32_t, sign = 0x80000000u); - BOOST_STATIC_CONSTANT(uint32_t, exponent = 0x7fff0000); - BOOST_STATIC_CONSTANT(uint32_t, flag = 0x00008000); - BOOST_STATIC_CONSTANT(uint32_t, significand = 0x00007fff); + static constexpr uint32_t sign = 0x80000000u; + static constexpr uint32_t exponent = 0x7fff0000; + static constexpr uint32_t flag = 0x00008000; + static constexpr uint32_t significand = 0x00007fff; typedef uint32_t bits; @@ -371,10 +391,10 @@ struct fp_traits_non_native { typedef ieee_copy_leading_bits_tag method; - BOOST_STATIC_CONSTANT(uint32_t, sign = 0x80000000u); - BOOST_STATIC_CONSTANT(uint32_t, exponent = 0x7ff00000); - BOOST_STATIC_CONSTANT(uint32_t, flag = 0x00000000); - BOOST_STATIC_CONSTANT(uint32_t, significand = 0x000fffff); + static constexpr uint32_t sign = 0x80000000u; + static constexpr uint32_t exponent = 0x7ff00000; + static constexpr uint32_t flag = 0x00000000; + static constexpr uint32_t significand = 0x000fffff; typedef uint32_t bits; @@ -390,10 +410,10 @@ struct fp_traits_non_native private: -#if BOOST_ENDIAN_BIG_BYTE - BOOST_STATIC_CONSTANT(int, offset_ = 0); -#elif BOOST_ENDIAN_LITTLE_BYTE - BOOST_STATIC_CONSTANT(int, offset_ = 12); +#if BOOST_MATH_ENDIAN_BIG_BYTE + static constexpr int offset_ = 0; +#elif BOOST_MATH_ENDIAN_LITTLE_BYTE + static constexpr int offset_ = 12; #else static_assert(false, "Endian type could not be identified"); #endif @@ -416,10 +436,10 @@ struct fp_traits_non_native { typedef ieee_copy_leading_bits_tag method; - BOOST_STATIC_CONSTANT(uint32_t, sign = 0x80000000u); - BOOST_STATIC_CONSTANT(uint32_t, exponent = 0x7fff0000); - BOOST_STATIC_CONSTANT(uint32_t, flag = 0x00008000); - BOOST_STATIC_CONSTANT(uint32_t, significand = 0x00007fff); + static constexpr uint32_t sign = 0x80000000u; + static constexpr uint32_t exponent = 0x7fff0000; + static constexpr uint32_t flag = 0x00008000; + static constexpr uint32_t significand = 0x00007fff; // copy 1st, 2nd, 5th and 6th byte. 3rd and 4th byte are padding. @@ -452,10 +472,10 @@ struct fp_traits_non_native { typedef ieee_copy_leading_bits_tag method; - BOOST_STATIC_CONSTANT(uint32_t, sign = 0x80000000u); - BOOST_STATIC_CONSTANT(uint32_t, exponent = 0x7fff0000); - BOOST_STATIC_CONSTANT(uint32_t, flag = 0x00000000); - BOOST_STATIC_CONSTANT(uint32_t, significand = 0x0000ffff); + static constexpr uint32_t sign = 0x80000000u; + static constexpr uint32_t exponent = 0x7fff0000; + static constexpr uint32_t flag = 0x00000000; + static constexpr uint32_t significand = 0x0000ffff; typedef uint32_t bits; @@ -471,10 +491,10 @@ struct fp_traits_non_native private: -#if BOOST_ENDIAN_BIG_BYTE - BOOST_STATIC_CONSTANT(int, offset_ = 0); -#elif BOOST_ENDIAN_LITTLE_BYTE - BOOST_STATIC_CONSTANT(int, offset_ = 12); +#if BOOST_MATH_ENDIAN_BIG_BYTE + static constexpr int offset_ = 0; +#elif BOOST_MATH_ENDIAN_LITTLE_BYTE + static constexpr int offset_ = 12; #else static_assert(false, "Endian type could not be identified"); #endif diff --git a/include/boost/math/tools/config.hpp b/include/boost/math/tools/config.hpp index 6dc6bc110..2f8c16be1 100644 --- a/include/boost/math/tools/config.hpp +++ b/include/boost/math/tools/config.hpp @@ -11,7 +11,6 @@ #endif #include -#include #include #include // for min and max #include From 004805e21becd5662863c7a857c418fa2f574b5f Mon Sep 17 00:00:00 2001 From: Matt Borland Date: Thu, 25 Mar 2021 19:04:20 +0300 Subject: [PATCH 7/7] Add _WIN32 --- include/boost/math/special_functions/detail/fp_traits.hpp | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/include/boost/math/special_functions/detail/fp_traits.hpp b/include/boost/math/special_functions/detail/fp_traits.hpp index 2eb67215a..80b3f692e 100644 --- a/include/boost/math/special_functions/detail/fp_traits.hpp +++ b/include/boost/math/special_functions/detail/fp_traits.hpp @@ -42,9 +42,17 @@ With these techniques, the code could be simplified. #else // Does not have compliant C++20 +#ifdef _WIN32 + +#define BOOST_MATH_ENDIAN_BIG_BYTE 1 +#define BOOST_MATH_ENDIAN_LITTLE_BYTE 0 + +#else + #define BOOST_MATH_ENDIAN_BIG_BYTE (__BYTE_ORDER__ == __ORDER_BIG_ENDIAN__) #define BOOST_MATH_ENDIAN_LITTLE_BYTE (__BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__) +#endif // Windows or POSIX #endif // Standalone mode #endif // Endian