From 12193b184bf733b87661326de5059c016be863f4 Mon Sep 17 00:00:00 2001 From: universenox Date: Wed, 10 Jul 2019 19:39:54 -0400 Subject: [PATCH] fix bug with big precision --- include/real/const_precision_iterator.hpp | 11 +++++------ include/real/real_explicit.hpp | 10 ++-------- 2 files changed, 7 insertions(+), 14 deletions(-) diff --git a/include/real/const_precision_iterator.hpp b/include/real/const_precision_iterator.hpp index 2230fd7..91bf5d7 100644 --- a/include/real/const_precision_iterator.hpp +++ b/include/real/const_precision_iterator.hpp @@ -223,10 +223,9 @@ namespace boost { * * @return a boost::real::const_precision_iterator of the number. */ - const_precision_iterator cend() const { - const_precision_iterator it(*this); - it.iterate_n_times(this->max_precision() - 1); - return it; + const_precision_iterator cend() { + this->iterate_n_times(this->max_precision() - _precision); + return *this; } interval get_interval() const { @@ -287,8 +286,8 @@ namespace boost { // If the explicit number didn't reaches the full precision (the end) // then the number interval is defined by truncation. - for(int i = 0; i < n; i++) { - this->_approximation_interval.lower_bound.push_back(real.digits()[this->_precision]); + for(int i = _precision; i < _precision + n; i++) { + this->_approximation_interval.lower_bound.push_back(real.digits()[i]); } this->_approximation_interval.upper_bound.clear(); diff --git a/include/real/real_explicit.hpp b/include/real/real_explicit.hpp index 6365886..798e137 100644 --- a/include/real/real_explicit.hpp +++ b/include/real/real_explicit.hpp @@ -27,9 +27,6 @@ namespace boost { // TODO: Add normalizations to the constructors exact_number explicit_number; - // The number max precision is the same as the explicit number digits size. - unsigned int _maximum_precision = 1; - public: /** @@ -105,7 +102,6 @@ namespace boost { for (const auto& c : decimal_part ) { explicit_number.digits.push_back(c - '0'); } - this->_maximum_precision = (int)this->_digits.size(); } /** @@ -117,8 +113,7 @@ namespace boost { * @param digits - an initializer_list that represents the number digits. * @param exponent - an integer representing the number exponent. */ - real_explicit(std::initializer_list digits, int exponent) : explicit_number(digits, exponent), - _maximum_precision((int)explicit_number.digits.size()) + real_explicit(std::initializer_list digits, int exponent) : explicit_number(digits, exponent) {}; /** @@ -134,8 +129,7 @@ namespace boost { * the number is positive, otherwise is negative. */ real_explicit(std::initializer_list digits, int exponent, bool positive) : - explicit_number(digits,exponent,positive) , - _maximum_precision((int)explicit_number.digits.size()) + explicit_number(digits,exponent,positive) {}; /**