1 #ifndef BOOST_REAL_BOUNDARY_HPP 2 #define BOOST_REAL_BOUNDARY_HPP 5 #include <real/boundary_helper.hpp> 16 std::vector<int> digits = {};
49 if (this->positive != other.positive) {
50 return !this->positive;
54 if (this->exponent == other.exponent) {
55 return boost::real::helper::aligned_vectors_is_lower(this->digits,
59 return this->exponent < other.exponent;
62 if (this->exponent == other.exponent) {
63 return boost::real::helper::aligned_vectors_is_lower(other.digits,
67 return other.exponent < this->exponent;
79 if (this->positive != other.positive) {
80 return this->positive;
84 if (this->exponent == other.exponent) {
85 return boost::real::helper::aligned_vectors_is_lower(other.digits, this->digits);
88 return this->exponent > other.exponent;
91 if (this->exponent == other.exponent) {
92 return boost::real::helper::aligned_vectors_is_lower(this->digits, other.digits);
95 return other.exponent > this->exponent;
106 return !(*
this < other || other < *
this);
115 std::basic_string<char> result =
"";
117 if (!this->positive) {
122 if ((this->exponent < -10) || (this->exponent > (
int)this->digits.size() + 10)) {
125 for (
const auto& d: this->digits) {
126 result += std::to_string(d);
129 result +=
"e" + std::to_string(this->exponent);
133 if (this->exponent <= 0) {
136 for (
int i = this->exponent; i < (int) this->digits.size(); ++i) {
140 result += std::to_string(this->digits[i]);
145 int digit_amount = std::max(this->exponent, (
int) this->digits.size());
146 for (
int i = 0; i < digit_amount; ++i) {
148 if (i == this->exponent) {
152 if (i < (
int) this->digits.size()) {
153 result += std::to_string(this->digits[i]);
159 if (result.back() ==
'.') {
175 this->digits.swap(other.digits);
176 std::swap(this->exponent, other.exponent);
177 std::swap(this->positive, other.positive);
187 this->digits.push_back(digit);
197 this->digits.insert(this->digits.begin(), digit);
205 while (this->digits.size() > 1 && this->digits.front() == 0) {
206 this->digits.erase(this->digits.begin());
210 while (this->digits.size() > 1 && this->digits.back() == 0) {
211 this->digits.pop_back();
215 if (this->digits.size() == 1 && this->digits.front() == 0) {
217 this->positive =
true;
226 while (this->digits.size() > 1 && this->digits.front() == 0) {
227 this->digits.erase(this->digits.begin());
236 this->digits.clear();
246 return this->digits[n];
255 return this->digits.size();
261 #endif //BOOST_REAL_BOUNDARY_HPP bool operator<(const boundary &other) const
Lower comparator operator: It compares the *this boost::real::boundary with the other boost::real::bo...
Definition: boundary.hpp:47
Definition: boundary.hpp:7
std::basic_string< char > as_string() const
Generates a string representation of the boost::real::boundary.
Definition: boundary.hpp:114
void clear()
ir clears the number digits.
Definition: boundary.hpp:235
bool operator==(const boundary &other) const
Equality comparator operator: It compares the *this boost::real::boundary with the other boost::real:...
Definition: boundary.hpp:105
void push_front(int digit)
add the digit parameter as a new digit of the boost::real::boundary. The digit is added in the left s...
Definition: boundary.hpp:196
void push_back(int digit)
add the digit parameter as a new digit of the boost::real::boundary. The digit is added in the right ...
Definition: boundary.hpp:186
void swap(boundary &other)
Swaps the boost::real::boundary value with the value of the other boost::real::boundary. This operation is a more preformant form of swapping to boost::real::boundaries.
Definition: boundary.hpp:174
bool operator>(const boundary &other) const
Greater comparator operator: It compares the *this boost::real::boundary with the other boost::real::...
Definition: boundary.hpp:77
void normalize()
Removes extra zeros at the sides to convert the number representation into a normalized representatio...
Definition: boundary.hpp:204
boundary & operator=(const boundary &other)=default
Default asignment operator.
void normalize_left()
Removes extra zeros at the left side to convert the number representation into a semi normalized repr...
Definition: boundary.hpp:225
Explicitly represents a number as a vector of digits with a sign and an exponent. ...
Definition: boundary.hpp:15
boundary()=default
default constructor: It construct a representation of the number zero.
int & operator[](int n)
Returns the n-th digit of the boost::real::boundary.
Definition: boundary.hpp:245
unsigned long size()
It return the amount of digit of the boost::real::boundary.
Definition: boundary.hpp:254