mirror of
https://github.com/boostorg/math.git
synced 2026-01-19 04:22:09 +00:00
Remove boost.integer dependency
This commit is contained in:
@@ -10,10 +10,14 @@
|
||||
#ifndef BOOST_MATH_COMMON_FACTOR_HPP
|
||||
#define BOOST_MATH_COMMON_FACTOR_HPP
|
||||
|
||||
#ifndef BOOST_MATH_STANDALONE
|
||||
#include <boost/math/common_factor_ct.hpp>
|
||||
#include <boost/math/common_factor_rt.hpp>
|
||||
#include <boost/math/tools/header_deprecated.hpp>
|
||||
|
||||
BOOST_HEADER_DEPRECATED("<boost/integer/common_factor.hpp>");
|
||||
|
||||
BOOST_MATH_HEADER_DEPRECATED("<boost/integer/common_factor.hpp>");
|
||||
#else
|
||||
#error Common factor is not available in standalone mode because it requires boost.integer.
|
||||
#endif // BOOST_MATH_STANDALONE
|
||||
|
||||
#endif // BOOST_MATH_COMMON_FACTOR_HPP
|
||||
|
||||
@@ -10,6 +10,7 @@
|
||||
#ifndef BOOST_MATH_COMMON_FACTOR_CT_HPP
|
||||
#define BOOST_MATH_COMMON_FACTOR_CT_HPP
|
||||
|
||||
#ifndef BOOST_MATH_STANDALONE
|
||||
#include <boost/integer/common_factor_ct.hpp>
|
||||
#include <boost/math/tools/header_deprecated.hpp>
|
||||
|
||||
@@ -26,6 +27,8 @@ namespace math
|
||||
|
||||
} // namespace math
|
||||
} // namespace boost
|
||||
|
||||
#else
|
||||
#error Common factor is not available in standalone mode because it requires boost.integer.
|
||||
#endif // BOOST_MATH_STANDALONE
|
||||
|
||||
#endif // BOOST_MATH_COMMON_FACTOR_CT_HPP
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
#ifndef BOOST_MATH_COMMON_FACTOR_RT_HPP
|
||||
#define BOOST_MATH_COMMON_FACTOR_RT_HPP
|
||||
|
||||
#ifndef BOOST_MATH_STANDALONE
|
||||
#include <boost/integer/common_factor_rt.hpp>
|
||||
#include <boost/math/tools/header_deprecated.hpp>
|
||||
|
||||
@@ -22,5 +23,8 @@ namespace boost {
|
||||
using boost::integer::lcm_evaluator;
|
||||
}
|
||||
}
|
||||
#else
|
||||
#error Common factor is not available in standalone mode because it requires boost.integer.
|
||||
#endif // BOOST_MATH_STANDALONE
|
||||
|
||||
#endif // BOOST_MATH_COMMON_FACTOR_RT_HPP
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
// (C) Copyright Jeremy William Murphy 2016.
|
||||
|
||||
// (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)
|
||||
@@ -14,8 +14,57 @@
|
||||
#include <algorithm>
|
||||
#include <type_traits>
|
||||
#include <boost/math/tools/polynomial.hpp>
|
||||
|
||||
#ifndef BOOST_MATH_STANDALONE
|
||||
#include <boost/integer/common_factor_rt.hpp>
|
||||
|
||||
// std::gcd was introduced in C++17
|
||||
#elif (__cplusplus > 201700L || _MSVC_LANG > 201700L)
|
||||
|
||||
#define BOOST_MATH_CXX17_NUMERIC
|
||||
#include <numeric>
|
||||
#include <utility>
|
||||
#include <iterator>
|
||||
#include <type_traits>
|
||||
#include <boost/math/tools/assert.hpp>
|
||||
|
||||
namespace boost::integer {
|
||||
|
||||
template <typename Iter, typename T = typename std::iterator_traits<I>::value_type>
|
||||
std::pair<T, Iter> gcd_range(Iter first, Iter last) noexcept(std::is_arithmetic_v<T>)
|
||||
{
|
||||
using std::gcd;
|
||||
BOOST_MATH_ASSERT(first != last);
|
||||
|
||||
T d = *first;
|
||||
++first;
|
||||
while (d != T(1) && first != last)
|
||||
{
|
||||
d = gcd(d, *first);
|
||||
++first;
|
||||
}
|
||||
return std::make_pair(d, first);
|
||||
}
|
||||
|
||||
namespace gcd_detail {
|
||||
|
||||
template <typename EuclideanDomain>
|
||||
inline EuclideanDomain Euclid_gcd(EuclideanDomain a, EuclideanDomain b) noexcept(std::is_arithmetic_v<EuclideanDomain>)
|
||||
{
|
||||
using std::swap;
|
||||
while (b != EuclideanDomain(0))
|
||||
{
|
||||
a %= b;
|
||||
swap(a, b);
|
||||
}
|
||||
return a;
|
||||
}
|
||||
|
||||
} // namespace gcd_detail
|
||||
} // namespace boost::integer
|
||||
#error polynomial gcd can only be used in standalone mode with C++17 or higher
|
||||
#endif
|
||||
|
||||
namespace boost{
|
||||
|
||||
namespace integer {
|
||||
@@ -36,8 +85,6 @@ namespace boost{
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
namespace math{ namespace tools{
|
||||
|
||||
/* From Knuth, 4.6.1:
|
||||
@@ -88,7 +135,14 @@ namespace detail
|
||||
template <class T>
|
||||
T reduce_to_primitive(polynomial<T> &u, polynomial<T> &v)
|
||||
{
|
||||
#ifndef BOOST_MATH_STANDALONE
|
||||
using boost::integer::gcd;
|
||||
#elif defined(BOOST_MATH_CXX17_NUMERIC)
|
||||
using std::gcd;
|
||||
#else
|
||||
#error polynomial gcd can only be used in standalone mode with C++17 or higher
|
||||
#endif
|
||||
|
||||
T const u_cont = content(u), v_cont = content(v);
|
||||
u /= u_cont;
|
||||
v /= v_cont;
|
||||
|
||||
Reference in New Issue
Block a user