diff --git a/doc/html/boost_integer/cstdint.html b/doc/html/boost_integer/cstdint.html index cb0223f..5d2c1ba 100644 --- a/doc/html/boost_integer/cstdint.html +++ b/doc/html/boost_integer/cstdint.html @@ -3,7 +3,7 @@
![]() |
+Home | +Libraries | +People | +FAQ | +More | +
+ The extended Euclidean algorithm solves the integer relation mx + + ny = gcd(m, n) for + x and y. +
+#include <boost/integer/extended_euclidean.hpp> + +namespace boost { namespace integer { + +template<class Z> +struct euclidean_result_t { + Z gcd; + Z x; + Z y; +}; + + +template<class Z> +euclidean_result_t<Z> extended_euclidean(Z m, Z n); + +}} ++
int m = 12; +int n = 15; +auto res = extended_euclidean(m, n); + +int gcd = res.gcd; +int x = res.x; +int y = res.y; +// mx + ny = gcd(m,n) should now hold ++
+ Unlike most of the library, the extended Euclidean algorithm requires C++11 + features. +
++ Wagstaff, Samuel S., The Joy of Factoring, Vol. 68. + American Mathematical Soc., 2013. +
++ | + |
namespace boost { -namespace math +namespace integer { template < typename IntegerType > @@ -102,10 +102,10 @@ Object- Header: <boost/math/common_factor_rt.hpp> + Header: <boost/integer/common_factor_rt.hpp>
template < typename IntegerType > -class boost::math::gcd_evaluator +class boost::integer::gcd_evaluator { public: // Types @@ -120,11 +120,11 @@ };- The boost::math::gcd_evaluator class template defines a function object class - to return the greatest common divisor of two integers. The template is parameterized - by a single type, called IntegerType here. This type should be a numeric - type that represents integers. The result of the function object is always - nonnegative, even if either of the operator arguments is negative. + The boost::integer::gcd_evaluator class template defines a function object + class to return the greatest common divisor of two integers. The template + is parameterized by a single type, called IntegerType here. This type should + be a numeric type that represents integers. The result of the function object + is always nonnegative, even if either of the operator arguments is negative.
This function object class template is used in the corresponding version @@ -144,10 +144,10 @@ Object
- Header: <boost/math/common_factor_rt.hpp> + Header: <boost/integer/common_factor_rt.hpp>
template < typename IntegerType > -class boost::math::lcm_evaluator +class boost::integer::lcm_evaluator { public: // Types @@ -162,13 +162,13 @@ };- The boost::math::lcm_evaluator class template defines a function object class - to return the least common multiple of two integers. The template is parameterized - by a single type, called IntegerType here. This type should be a numeric - type that represents integers. The result of the function object is always - nonnegative, even if either of the operator arguments is negative. If the - least common multiple is beyond the range of the integer type, the results - are undefined. + The boost::integer::lcm_evaluator class template defines a function object + class to return the least common multiple of two integers. The template is + parameterized by a single type, called IntegerType here. This type should + be a numeric type that represents integers. The result of the function object + is always nonnegative, even if either of the operator arguments is negative. + If the least common multiple is beyond the range of the integer type, the + results are undefined.
This function object class template is used in the corresponding version @@ -188,13 +188,13 @@ Determination
- Header: <boost/math/common_factor_rt.hpp> + Header: <boost/integer/common_factor_rt.hpp>
template < typename IntegerType > -constexpr IntegerType boost::math::gcd( IntegerType const &a, IntegerType const &b ); +constexpr IntegerType boost::integer::gcd( IntegerType const &a, IntegerType const &b ); template < typename IntegerType > -constexpr IntegerType boost::math::lcm( IntegerType const &a, IntegerType const &b ); +constexpr IntegerType boost::integer::lcm( IntegerType const &a, IntegerType const &b ); template < typename IntegerType, typename... Args > constexpr IntegerType gcd( IntegerType const &a, IntegerType const &b, Args const&... ); @@ -211,8 +211,8 @@ lcm_range(I first, I last);- The boost::math::gcd function template returns the greatest common (nonnegative) - divisor of the two integers passed to it.
boost::math::gcd_range
+ The boost::integer::gcd function template returns the greatest common (nonnegative) + divisor of the two integers passed to it.boost::integer::gcd_range
is the iteration of the above gcd algorithm over a range, returning the greatest common divisor of all the elements. The algorithm terminates when the gcd reaches unity or the end of the range. Thus it also returns the iterator @@ -222,7 +222,7 @@ to reach unity.- The boost::math::lcm function template returns the least common (nonnegative) + The boost::integer::lcm function template returns the least common (nonnegative) multiple of the two integers passed to it. As with gcd, there are range and variadic versions of the function for more than 2 arguments.
@@ -249,17 +249,17 @@- Header: <boost/math/common_factor_ct.hpp> + Header: <boost/integer/common_factor_ct.hpp>
typedef unspecified static_gcd_type; template < static_gcd_type Value1, static_gcd_type Value2 > -struct boost::math::static_gcd : public mpl::integral_c<static_gcd_type, implementation_defined> +struct boost::integer::static_gcd : public mpl::integral_c<static_gcd_type, implementation_defined> { }; template < static_gcd_type Value1, static_gcd_type Value2 > -struct boost::math::static_lcm : public mpl::integral_c<static_gcd_type, implementation_defined> +struct boost::integer::static_lcm : public mpl::integral_c<static_gcd_type, implementation_defined> { };@@ -271,8 +271,8 @@ long for some older compilers.- The boost::math::static_gcd and boost::math::static_lcm class templates take - two value-based template parameters of the static_gcd_type + The boost::integer::static_gcd and boost::integer::static_lcm class templates + take two value-based template parameters of the static_gcd_type type and inherit from the type
boost::mpl::integral_c
. Inherited from the base class, they have a member value that is the greatest common factor or least common multiple, respectively, of the template arguments. @@ -283,7 +283,7 @@ Example -#include <boost/math/common_factor.hpp> +#include <boost/integer/common_factor.hpp> #include <algorithm> #include <iterator> #include <iostream> @@ -294,29 +294,29 @@ using std::endl; cout << "The GCD and LCM of 6 and 15 are " - << boost::math::gcd(6, 15) << " and " - << boost::math::lcm(6, 15) << ", respectively." + << boost::integer::gcd(6, 15) << " and " + << boost::integer::lcm(6, 15) << ", respectively." << endl; cout << "The GCD and LCM of 8 and 9 are " - << boost::math::static_gcd<8, 9>::value + << boost::integer::static_gcd<8, 9>::value << " and " - << boost::math::static_lcm<8, 9>::value + << boost::integer::static_lcm<8, 9>::value << ", respectively." << endl; int a[] = { 4, 5, 6 }, b[] = { 7, 8, 9 }, c[3]; - std::transform( a, a + 3, b, c, boost::math::gcd_evaluator<int>() ); + std::transform( a, a + 3, b, c, boost::integer::gcd_evaluator<int>() ); std::copy( c, c + 3, std::ostream_iterator<int>(cout, " ") ); }- This header simply includes the headers <boost/math/common_factor_ct.hpp> - and <boost/math/common_factor_rt.hpp>. + This header simply includes the headers <boost/integer/common_factor_ct.hpp> + and <boost/integer/common_factor_rt.hpp>.
Note this is a legacy header: it used to contain the actual implementation, @@ -329,7 +329,7 @@ Demonstration Program
- The program common_factor_test.cpp + The program common_factor_test.cpp is a demonstration of the results from instantiating various examples of the run-time GCD and LCM function templates and the compile-time GCD and LCM class templates. (The run-time GCD and LCM class templates are tested @@ -344,7 +344,7 @@ The greatest common divisor and least common multiple functions are greatly used in some numeric contexts, including some of the other Boost libraries. Centralizing these functions to one header improves code factoring and eases - maintainence. + maintenance.