From 4991d82385c9cb215ce5230c90b452a8b7f31d91 Mon Sep 17 00:00:00 2001 From: jzmaddock Date: Mon, 24 Apr 2017 19:19:48 +0100 Subject: [PATCH] Need to take abs of return value in short-circuit gcd code. --- include/boost/integer/common_factor_rt.hpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/include/boost/integer/common_factor_rt.hpp b/include/boost/integer/common_factor_rt.hpp index d27f094..2f65d67 100644 --- a/include/boost/integer/common_factor_rt.hpp +++ b/include/boost/integer/common_factor_rt.hpp @@ -447,9 +447,9 @@ template inline BOOST_CXX14_CONSTEXPR Integer gcd(Integer const &a, Integer const &b) BOOST_GCD_NOEXCEPT(Integer) { if(a == (std::numeric_limits::min)()) - return a == static_cast(0) ? b : gcd(static_cast(a % b), b); + return a == static_cast(0) ? gcd_detail::gcd_traits::abs(b) : gcd(static_cast(a % b), b); else if (b == (std::numeric_limits::min)()) - return b == static_cast(0) ? a : gcd(a, static_cast(b % a)); + return b == static_cast(0) ? gcd_detail::gcd_traits::abs(a) : gcd(a, static_cast(b % a)); return gcd_detail::optimal_gcd_select(static_cast(gcd_detail::gcd_traits::abs(a)), static_cast(gcd_detail::gcd_traits::abs(b))); }