diff --git a/a.out b/a.out deleted file mode 100755 index ab167ba..0000000 Binary files a/a.out and /dev/null differ diff --git a/include/real/exact_number.hpp b/include/real/exact_number.hpp index a5adc71..f3658e1 100644 --- a/include/real/exact_number.hpp +++ b/include/real/exact_number.hpp @@ -5,12 +5,20 @@ #include #include #include +<<<<<<< HEAD #include +======= +#include +>>>>>>> finished exponential, made changes to division namespace boost { namespace real { struct exact_number { +<<<<<<< HEAD using exponent_t = int; +======= + typedef int exponent_t; +>>>>>>> finished exponential, made changes to division std::vector digits = {}; exponent_t exponent = 0; @@ -216,7 +224,11 @@ namespace boost { if (divisor == tmp) { this->exponent = exponent_dif + 1; +<<<<<<< HEAD this->positive = positive; +======= + (*this).positive = positive; +>>>>>>> finished exponential, made changes to division return; } @@ -226,7 +238,11 @@ namespace boost { return; } +<<<<<<< HEAD exact_number zero = exact_number(); +======= + exact_number zero = exact_number(); +>>>>>>> finished exponential, made changes to division if (divisor == zero) { throw(boost::real::divide_by_zero()); @@ -250,7 +266,11 @@ namespace boost { (*this) = left + distance; // N/D = Q -> QD -N = 0 residual = (*this) * divisor - numerator; +<<<<<<< HEAD if (residual == zero) { +======= + if (residual == 0) { +>>>>>>> finished exponential, made changes to division this->exponent += exponent_dif; this->positive = positive; return; @@ -290,7 +310,11 @@ namespace boost { // recalculate residual N/D = Q ---> QD - N = residual residual = ((*this) * divisor) - numerator; residual.normalize(); +<<<<<<< HEAD } +======= + } // end while +>>>>>>> finished exponential, made changes to division // at this point, we may have exited early. we should be within +- min_boundary_p of the solution. // truncate (*this) @@ -405,9 +429,14 @@ namespace boost { if(this->digits[index] != 0) { --this->digits[index]; keep_carrying = false; +<<<<<<< HEAD } else { // digits[index] == 0, we keep carrying this->digits[index] = DIGIT_MAX; } +======= + } else // digits[index] == 0, we keep carrying + this->digits[index] = DIGIT_MAX; +>>>>>>> finished exponential, made changes to division --index; } // we should be ok at this point because the first number in digits should != 0 @@ -423,9 +452,21 @@ namespace boost { /// ctor from vector of digits, integer exponent, and optional bool positive exact_number(std::vector vec, int exp, bool pos = true) : digits(vec), exponent(exp), positive(pos) {}; +<<<<<<< HEAD /// ctor from any integral type template::value>> exact_number(I x) { +======= + + // exact_number(std::initializer_list list, int exp, bool pos= true) : + // digits(list), exponent(exp), positive(pos) {}; + + /// ctor from any integral type + template + exact_number(I x) { + static_assert(std::numeric_limits::is_integer); + +>>>>>>> finished exponential, made changes to division if (x < 0) positive = false; else @@ -439,6 +480,7 @@ namespace boost { } } +<<<<<<< HEAD explicit exact_number (const std::string& number) { std::regex decimal("((\\+|-)?[[:digit:]]*)(\\.(([[:digit:]]+)?))?((e|E)(((\\+|-)?)[[:digit:]]+))?"); if (!std::regex_match (number, decimal)) @@ -491,6 +533,8 @@ namespace boost { } } +======= +>>>>>>> finished exponential, made changes to division /** * @brief *Copy constructor:* It constructs a new boost::real::exact_number that is a copy of the * other boost::real::exact_number. @@ -555,7 +599,11 @@ namespace boost { if (this->digits == zero || this->digits.empty()) { return !(other.digits == zero || other.positive || other.digits.empty()); } else { +<<<<<<< HEAD if ((other.digits == zero) && this->positive) +======= + if ((other.digits == zero || other.digits.empty()) && this->positive) +>>>>>>> finished exponential, made changes to division return true; } @@ -579,11 +627,19 @@ namespace boost { } bool operator>=(const exact_number& other) const { +<<<<<<< HEAD return (!((*this) < other)); } bool operator<=(const exact_number& other) const { return (!((*this) > other)); +======= + return (((*this) == other) || ((*this) > other)); + } + + bool operator<=(const exact_number& other) const { + return (((*this) == other) || ((*this) < other)); +>>>>>>> finished exponential, made changes to division } /** @@ -662,7 +718,6 @@ namespace boost { *this = *this * other; } - /** * @brief Generates a string representation of the boost::real::exact_number. * diff --git a/include/real/irrational_helpers.hpp b/include/real/irrational_helpers.hpp index 185ef59..5a1c37e 100644 --- a/include/real/irrational_helpers.hpp +++ b/include/real/irrational_helpers.hpp @@ -4,7 +4,11 @@ #include #include #include +<<<<<<< HEAD #include +======= +#include +>>>>>>> finished exponential, made changes to division namespace boost { namespace real { @@ -92,6 +96,7 @@ namespace boost { return current_value.digits[n]; } +<<<<<<< HEAD int pi_get_nth_digit(unsigned int n) { if (n > 2000) @@ -100,6 +105,8 @@ namespace boost { exact_number pi("3.14159265358979323846264338327950288419716939937510582097494459230781640628620899862803482534211706798214808651328230664709384460955058223172535940812848111745028410270193852110555964462294895493038196442881097566593344612847564823378678316527120190914564856692346034861045432664821339360726024914127372458700660631558817488152092096282925409171536436789259036001133053054882046652138414695194151160943305727036575959195309218611738193261179310511854807446237996274956735188575272489122793818301194912983367336244065664308602139494639522473719070217986094370277053921717629317675238467481846766940513200056812714526356082778577134275778960917363717872146844090122495343014654958537105079227968925892354201995611212902196086403441815981362977477130996051870721134999999837297804995105973173281609631859502445945534690830264252230825334468503526193118817101000313783875288658753320838142061717766914730359825349042875546873115956286388235378759375195778185778053217122680661300192787661119590921642019893809525720106548586327886593615338182796823030195203530185296899577362259941389124972177528347913151557485724245415069595082953311686172785588907509838175463746493931925506040092770167113900984882401285836160356370766010471018194295559619894676783744944825537977472684710404753464620804668425906949129331367702898915210475216205696602405803815019351125338243003558764024749647326391419927260426992279678235478163600934172164121992458631503028618297455570674983850549458858692699569092721079750930295532116534498720275596023648066549911988183479775356636980742654252786255181841757467289097777279380008164706001614524919217321721477235014144197356854816136115735255213347574184946843852332390739414333454776241686251898356948556209921922218427255025425688767179049460165346680498862723279178608578438382796797668145410095388378636095068006422512520511739298489608412848862694560424196528502221066118630674427862203919494504712371378696095636437191728746776465757396241389086583264599581339047802759009"); return pi[n]; } +======= +>>>>>>> finished exponential, made changes to division } } } diff --git a/include/real/real.hpp b/include/real/real.hpp index df8cfbc..57deeeb 100644 --- a/include/real/real.hpp +++ b/include/real/real.hpp @@ -494,7 +494,7 @@ namespace boost { * @param other - the right side operand boost::real::real number. */ void operator*=(real other) { - this->_real_p = + this->_real_p = std::make_shared(real_operation(this->_real_p, other._real_p, OPERATION::MULTIPLICATION)); } @@ -695,7 +695,7 @@ namespace boost { } inline boost::real::real operator "" _r(long double x) { - return boost::real::real (std::to_string(x)); + return boost::real::real(std::to_string(x)); } inline boost::real::real operator "" _r(unsigned long long x) { diff --git a/include/real/real_data.hpp b/include/real/real_data.hpp index 281ab2b..2bd17ee 100644 --- a/include/real/real_data.hpp +++ b/include/real/real_data.hpp @@ -226,11 +226,9 @@ namespace boost { if (residual.abs() > zero) { this->_approximation_interval.upper_bound.round_up(); } - // if both operands are numbers (not intervals), then we can skip doing the lower bound separately if (ro.get_rhs_itr().get_interval().is_a_number() && ro.get_lhs_itr().get_interval().is_a_number()) { _approximation_interval.lower_bound = quotient; - if (residual == zero) { _approximation_interval.upper_bound = _approximation_interval.lower_bound; } else { diff --git a/test.cpp b/test.cpp deleted file mode 100644 index 92b7b1e..0000000 --- a/test.cpp +++ /dev/null @@ -1,13 +0,0 @@ -#include -#include -#include - -std::optional boost::real::const_precision_iterator::maximum_precision = 10; - -int main() { - boost::real::real a("144"); // [100, 200] - boost::real::real b("12"); // [10 , 20] - boost::real::real result = b/a; // [100, 200] / [10, 20] = [100/20, 200/10] = [5, 20] - - std::cout << result << '\n'; -} \ No newline at end of file diff --git a/test/real_iterator_division_test.cpp b/test/real_iterator_division_test.cpp index 58218c5..371b30d 100644 --- a/test/real_iterator_division_test.cpp +++ b/test/real_iterator_division_test.cpp @@ -43,7 +43,6 @@ TEST_CASE("Operator / boost::real::const_precision_iterator") { // assumes max p boost::real::real result = b/a; // 12 / 144 // [10, 20] / [100, 200] = [10/200, 20/100] = [.05, .2] - auto result_it = result.get_real_itr().cbegin(); boost::real::interval expected_interval({}); @@ -56,7 +55,6 @@ TEST_CASE("Operator / boost::real::const_precision_iterator") { // assumes max p CHECK(expected_interval == result_it.get_interval()); result_it = result.get_real_itr().cend(); - // [12, 12] / [144, 144] = [.08333...3, .0833...4] expected_interval.lower_bound.positive = true; expected_interval.upper_bound.positive = true;