Skip to content

Commit

Permalink
Merge pull request #50 from bluescarni/division_improvements
Browse files Browse the repository at this point in the history
Division improvements
  • Loading branch information
bluescarni committed Feb 29, 2016
2 parents 3aed962 + 278aa52 commit 2eb2fe7
Show file tree
Hide file tree
Showing 17 changed files with 1,498 additions and 561 deletions.
7 changes: 7 additions & 0 deletions cmake_modules/PiranhaCompilerLinkerSettings.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -152,3 +152,10 @@ if(CMAKE_COMPILER_IS_CLANGXX OR CMAKE_COMPILER_IS_GNUCXX OR CMAKE_COMPILER_IS_IN
PIRANHA_CHECK_ENABLE_DEBUG_CXX_FLAG(-ftemplate-backtrace-limit=0)
PIRANHA_CHECK_ENABLE_DEBUG_CXX_FLAG(-fstack-protector-all)
endif()

# Clang specific configuration.
if(CMAKE_COMPILER_IS_CLANGXX)
# Clang is better at this flag than GCC, which emits a questionable warning when compiling
# the Python bindings.
PIRANHA_CHECK_ENABLE_DEBUG_CXX_FLAG(-Werror)
endif()
1 change: 0 additions & 1 deletion src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,6 @@ SET(DETAIL_HEADERS_LIST
detail/is_digit.hpp
detail/config_intel.hpp
detail/type_in_tuple.hpp
detail/gcd.hpp
detail/vector_merge_args.hpp
detail/divisor_series_fwd.hpp
detail/cf_mult_impl.hpp
Expand Down
11 changes: 8 additions & 3 deletions src/base_series_multiplier.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,9 @@ see https://www.gnu.org/licenses/. */

#include "config.hpp"
#include "detail/atomic_utils.hpp"
#include "detail/gcd.hpp"
#include "exceptions.hpp"
#include "key_is_multipliable.hpp"
#include "math.hpp"
#include "mp_integer.hpp"
#include "mp_rational.hpp"
#include "safe_cast.hpp"
Expand Down Expand Up @@ -162,12 +162,17 @@ struct base_series_multiplier_impl<Series,Derived,typename std::enable_if<is_mp_
// Compute the least common multiplier.
m_lcm = 1;
auto it_f = c1.end();
int_type g;
for (auto it = c1.begin(); it != it_f; ++it) {
m_lcm = (m_lcm * it->m_cf.den()) / gcd(m_lcm,it->m_cf.den());
math::gcd3(g,m_lcm,it->m_cf.den());
math::mul3(m_lcm,m_lcm,it->m_cf.den());
int_type::_divexact(m_lcm,m_lcm,g);
}
it_f = c2.end();
for (auto it = c2.begin(); it != it_f; ++it) {
m_lcm = (m_lcm * it->m_cf.den()) / gcd(m_lcm,it->m_cf.den());
math::gcd3(g,m_lcm,it->m_cf.den());
math::mul3(m_lcm,m_lcm,it->m_cf.den());
int_type::_divexact(m_lcm,m_lcm,g);
}
// All these computations involve only positive numbers,
// the GCD must always be positive.
Expand Down
58 changes: 0 additions & 58 deletions src/detail/gcd.hpp

This file was deleted.

4 changes: 2 additions & 2 deletions src/divisor.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,14 +44,14 @@ see https://www.gnu.org/licenses/. */
#include "config.hpp"
#include "detail/cf_mult_impl.hpp"
#include "detail/divisor_series_fwd.hpp"
#include "detail/gcd.hpp"
#include "detail/prepare_for_print.hpp"
#include "detail/series_fwd.hpp"
#include "detail/vector_merge_args.hpp"
#include "exceptions.hpp"
#include "hash_set.hpp"
#include "is_cf.hpp"
#include "is_key.hpp"
#include "math.hpp"
#include "mp_integer.hpp"
#include "pow.hpp"
#include "safe_cast.hpp"
Expand Down Expand Up @@ -162,7 +162,7 @@ class divisor
first_nonzero_found = true;
}
// NOTE: gcd(0,n) == n (or +-n, in our case) for all n, zero included.
cd = detail::gcd(cd,n);
math::gcd3(cd,cd,n);
}
if (cd != 1 && cd != -1) {
return false;
Expand Down
3 changes: 1 addition & 2 deletions src/divisor_series.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ see https://www.gnu.org/licenses/. */
#include "config.hpp"
#include "detail/divisor_series_fwd.hpp"
#include "detail/polynomial_fwd.hpp"
#include "detail/gcd.hpp"
#include "divisor.hpp"
#include "exceptions.hpp"
#include "forwarding.hpp"
Expand Down Expand Up @@ -319,7 +318,7 @@ class divisor_series: public power_series<ipow_substitutable_series<substitutabl
}
// NOTE: gcd(0,n) == n (or +-n, in our case) for all n, zero included.
// NOTE: the gcd computation here is safe as we are operating on integers.
cd = detail::gcd(cd,n);
math::gcd3(cd,cd,n);
}
// Common denominator could be negative.
if (cd.sign() < 0) {
Expand Down
Loading

0 comments on commit 2eb2fe7

Please sign in to comment.