Skip to content

Commit

Permalink
Implemented new maximum precision sytem with default static and parti…
Browse files Browse the repository at this point in the history
…cular values and a setter.
  • Loading branch information
Laouen committed Aug 13, 2018
1 parent cfef3dc commit 91c5b20
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 14 deletions.
12 changes: 9 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -118,12 +118,18 @@ The boost::real::const_precision_iterator is a forward iterator [4] that iterate
### Other methods

1. boost::real::const_precision_iterator boost::real::cbegin()
1. boost::real::const_precision_iterator boost::real::cend()
2. boost::real::const_precision_iterator boost::real::cend()
3. unsigned int boost::real::maximum_precision()
4. void boost::real::set_maximum_precision(unsigned int)

> (1) Construct a new const_precision_iterator that iterate over the *this number precisions. The constructed iterator points to the first approximation interval (the ine with less precision).
> (2) Construct a new const_precision_iterator that iterate over the *this number precisions. The constructed iterator points to the last approximation interval (the one with more precision) within the maximum precision.
> (3) Returns the instance maximum precision at which the operators will throw a boost::real::precision_exception if they cannot determine the operation value before reaching the maximum precision.
> (4) Sets a new maximum precision. If the set maximum precision is zero, the static default maximum precision will be used instead.
## boost::real::const_precision_iterator interface

### Constructors
Expand Down Expand Up @@ -158,8 +164,8 @@ The boost::real::const_precision_iterator is a forward iterator [4] that iterate
#include <string>
#include <real/real.hpp>

int boost::real::real::maximum_precision = 10;
int boost::real::real_algorithm::maximum_precision = 10;
unsigned int boost::real::real::maximum_precision = 10;
unsigned int boost::real::real_algorithm::maximum_precision = 10;

int main() {
boost::real::real c = (std::string)"0.999999";
Expand Down
17 changes: 10 additions & 7 deletions include/real/real.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -555,7 +555,7 @@ namespace boost {
*
* @return and integer with the maximum allowed precision.
*/
int max_precision() const {
unsigned int max_precision() const {
if (this->_maximum_precision == 0) {
return boost::real::real::maximum_precision;
}
Expand All @@ -566,6 +566,9 @@ namespace boost {
/**
* @brief Set a new maximum precision for the instance.
*
* @note Setting zero as the maximum precision causes the instance to use the default
* static unsigned int boost::real::real::maximum_precision.
*
* @param maximum_precision - an unsigned int to set as the new precision.
*/
void set_maximum_precision(unsigned int maximum_precision) {
Expand Down Expand Up @@ -759,8 +762,8 @@ namespace boost {
auto this_it = this->cbegin();
auto other_it = other.cbegin();

int current_precision = std::max(this->max_precision(), other.max_precision());
for (int p = 0; p < current_precision; ++p) {
unsigned int current_precision = std::max(this->max_precision(), other.max_precision());
for (unsigned int p = 0; p < current_precision; ++p) {
// Get more precision
++this_it;
++other_it;
Expand Down Expand Up @@ -800,8 +803,8 @@ namespace boost {
auto this_it = this->cbegin();
auto other_it = other.cbegin();

int current_precision = std::max(this->max_precision(), other.max_precision());
for (int p = 0; p < current_precision; ++p) {
unsigned int current_precision = std::max(this->max_precision(), other.max_precision());
for (unsigned int p = 0; p < current_precision; ++p) {
// Get more precision
++this_it;
++other_it;
Expand Down Expand Up @@ -841,8 +844,8 @@ namespace boost {
auto this_it = this->cbegin();
auto other_it = other.cbegin();

int current_precision = std::max(this->max_precision(), other.max_precision());
for (int p = 0; p < current_precision; ++p) {
unsigned int current_precision = std::max(this->max_precision(), other.max_precision());
for (unsigned int p = 0; p < current_precision; ++p) {
// Get more precision
++this_it;
++other_it;
Expand Down
4 changes: 2 additions & 2 deletions include/real/real_algorithm.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ namespace boost {
*
* @return an integer with the maximum allowed precision.
*/
int max_precision() const {
unsigned int max_precision() const {
return boost::real::real_algorithm::maximum_precision;
}

Expand Down Expand Up @@ -313,7 +313,7 @@ namespace boost {
*/
std::ostream& operator<<(std::ostream& os, const boost::real::real_algorithm& r) {
auto it = r.cbegin();
for (int i = 0; i <= r.max_precision(); i++) {
for (unsigned int i = 0; i <= r.max_precision(); i++) {
++it;
}
os << it.approximation_interval;
Expand Down
4 changes: 2 additions & 2 deletions include/real/real_explicit.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -358,7 +358,7 @@ namespace boost {
*
* @return and integer with the maximum allowed precision.
*/
int max_precision() const {
unsigned int max_precision() const {
return this->_maximum_precision;
}

Expand Down Expand Up @@ -452,7 +452,7 @@ namespace boost {
*/
std::ostream& operator<<(std::ostream& os, const boost::real::real_explicit& r) {
auto it = r.cbegin();
for (int i = 0; i <= r.max_precision(); i++) {
for (unsigned int i = 0; i <= r.max_precision(); i++) {
++it;
}
os << it.approximation_interval;
Expand Down

0 comments on commit 91c5b20

Please sign in to comment.