From 7ab7d21eaec11cbef821f9b7385a8b39565697e4 Mon Sep 17 00:00:00 2001 From: John Maddock Date: Fri, 7 May 2010 15:36:09 +0000 Subject: [PATCH] Fix failures when used with an expression-template enabled number type such as the gmpxx clases. Add additional concept check for integer code using gmp classes. Fixes #4139. [SVN r61837] --- config/Jamfile.v2 | 3 +++ config/has_gmpxx.cpp | 7 ++++++ include/boost/math/common_factor_rt.hpp | 8 +++---- include/boost/math/special_functions/cbrt.hpp | 7 +++++- test/Jamfile.v2 | 1 + test/test_common_factor_gmpxx.cpp | 22 +++++++++++++++++++ 6 files changed, 43 insertions(+), 5 deletions(-) create mode 100644 config/has_gmpxx.cpp create mode 100644 test/test_common_factor_gmpxx.cpp diff --git a/config/Jamfile.v2 b/config/Jamfile.v2 index 3fb445b08..0ac348e8e 100644 --- a/config/Jamfile.v2 +++ b/config/Jamfile.v2 @@ -13,10 +13,13 @@ obj has_long_double_support : has_long_double_support.cpp ; obj has_mpfr_class : has_mpfr_class.cpp : $(gmp_path) $(gmp_path)/mpfr $(gmp_path)/gmpfrxx ; obj has_ntl_rr : has_ntl_rr.cpp : $(ntl-path)/include ; +obj has_gmpxx : has_gmpxx.cpp : + $(gmp_path) $(gmp_path)/mpfr $(gmp_path)/gmpfrxx ; explicit has_long_double_support ; explicit has_mpfr_class ; explicit has_ntl_rr ; +explicit has_gmpxx ; diff --git a/config/has_gmpxx.cpp b/config/has_gmpxx.cpp new file mode 100644 index 000000000..edf62d8c7 --- /dev/null +++ b/config/has_gmpxx.cpp @@ -0,0 +1,7 @@ +// Copyright John Maddock 2008. +// 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 + diff --git a/include/boost/math/common_factor_rt.hpp b/include/boost/math/common_factor_rt.hpp index f45f3a029..ef2a967da 100644 --- a/include/boost/math/common_factor_rt.hpp +++ b/include/boost/math/common_factor_rt.hpp @@ -78,8 +78,8 @@ namespace detail RingType gcd_euclidean ( - RingType a, - RingType b + RingType a, + RingType b ) { // Avoid repeated construction @@ -116,7 +116,7 @@ namespace detail IntegerType const zero = static_cast( 0 ); IntegerType const result = gcd_euclidean( a, b ); - return ( result < zero ) ? -result : result; + return ( result < zero ) ? static_cast(-result) : result; } // Greatest common divisor for unsigned binary integers @@ -212,7 +212,7 @@ namespace detail IntegerType const zero = static_cast( 0 ); IntegerType const result = lcm_euclidean( a, b ); - return ( result < zero ) ? -result : result; + return ( result < zero ) ? static_cast(-result) : result; } // Function objects to find the best way of computing GCD or LCM diff --git a/include/boost/math/special_functions/cbrt.hpp b/include/boost/math/special_functions/cbrt.hpp index e6e5a2ad3..040f635d4 100644 --- a/include/boost/math/special_functions/cbrt.hpp +++ b/include/boost/math/special_functions/cbrt.hpp @@ -24,11 +24,16 @@ namespace boost{ namespace math{ namespace detail { +struct big_int_type +{ + operator boost::uintmax_t()const; +}; + template struct largest_cbrt_int_type { typedef typename mpl::if_< - boost::is_convertible, + boost::is_convertible, boost::uintmax_t, unsigned int >::type type; diff --git a/test/Jamfile.v2 b/test/Jamfile.v2 index fd9b48671..8997d87c5 100644 --- a/test/Jamfile.v2 +++ b/test/Jamfile.v2 @@ -752,6 +752,7 @@ run complex_test.cpp ../../test/build//boost_test_exec_monitor ; compile ntl_concept_check.cpp : [ check-target-builds ../config//has_ntl_rr : : no ] ; compile mpfr_concept_check.cpp : [ check-target-builds ../config//has_mpfr_class : : no ] ; +compile test_common_factor_gmpxx.cpp : [ check-target-builds ../config//has_gmpxx : : no ] ; build-project ../example ; diff --git a/test/test_common_factor_gmpxx.cpp b/test/test_common_factor_gmpxx.cpp new file mode 100644 index 000000000..27638d08c --- /dev/null +++ b/test/test_common_factor_gmpxx.cpp @@ -0,0 +1,22 @@ + +// (C) Copyright John Maddock 2010. +// 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 +#include + +template class boost::math::gcd_evaluator; +template class boost::math::lcm_evaluator; +template mpz_class boost::math::gcd(const mpz_class&, const mpz_class&); +template mpz_class boost::math::lcm(const mpz_class&, const mpz_class&); + +template mpz_class boost::math::detail::gcd_euclidean(const mpz_class, const mpz_class); +template mpz_class boost::math::detail::gcd_integer(const mpz_class&, const mpz_class&); +template mpz_class boost::math::detail::lcm_euclidean(const mpz_class&, const mpz_class&); +template mpz_class boost::math::detail::lcm_integer(const mpz_class&, const mpz_class&); + +int main() +{ +}