2 * (C) Copyright Nick Thompson 2018.
3 * Use, modification and distribution are subject to the
4 * Boost Software License, Version 1.0. (See accompanying file
5 * LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
7 #ifndef BOOST_INTEGER_EXTENDED_EUCLIDEAN_HPP
8 #define BOOST_INTEGER_EXTENDED_EUCLIDEAN_HPP
11 #include <boost/throw_exception.hpp>
12 #include <boost/core/swap.hpp>
13 #include <boost/core/enable_if.hpp>
15 namespace boost { namespace integer {
17 // From "The Joy of Factoring", Algorithm 2.7, with a small optimization to remove tmps from Wikipedia.
18 // Solves mx + ny = gcd(m,n). Returns tuple with (gcd(m,n), x, y).
21 struct euclidean_result_t
29 typename boost::enable_if_c< std::numeric_limits< Z >::is_signed, euclidean_result_t< Z > >::type
30 extended_euclidean(Z m, Z n)
34 BOOST_THROW_EXCEPTION(std::domain_error("extended_euclidean: arguments must be strictly positive"));
66 euclidean_result_t< Z > result;