-
Notifications
You must be signed in to change notification settings - Fork 7
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
changed max_precision for real #18
Open
SagnikDey92
wants to merge
2
commits into
BoostGSoC18:master
Choose a base branch
from
SagnikDey92:precision_fix
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -204,7 +204,9 @@ namespace boost { | |||||
* @param exponent - an integer representing the number exponent. | ||||||
*/ | ||||||
explicit real_algorithm(int (*get_nth_digit)(unsigned int), int exponent) | ||||||
: _get_nth_digit(get_nth_digit), _exponent(exponent), _positive(true) {} | ||||||
: _get_nth_digit(get_nth_digit), _exponent(exponent), _positive(true) { | ||||||
set_maximum_precision(15); | ||||||
} | ||||||
|
||||||
/** | ||||||
* @brief *Lambda function constructor with exponent and sign:* Creates a boost::real::real_algorithm instance | ||||||
|
@@ -224,7 +226,9 @@ namespace boost { | |||||
bool positive) | ||||||
: _get_nth_digit(get_nth_digit), | ||||||
_exponent(exponent), | ||||||
_positive(positive) {} | ||||||
_positive(positive) { | ||||||
set_maximum_precision(15); | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
} | ||||||
|
||||||
/** | ||||||
* @brief Returns the maximum allowed precision, if that precision is reached and an | ||||||
|
@@ -233,7 +237,7 @@ namespace boost { | |||||
* @return an integer with the maximum allowed precision. | ||||||
*/ | ||||||
unsigned int max_precision() const { | ||||||
return boost::real::real_algorithm::maximum_precision; | ||||||
return this->_maximum_precision; | ||||||
} | ||||||
|
||||||
/** | ||||||
|
@@ -281,7 +285,7 @@ namespace boost { | |||||
*/ | ||||||
const_precision_iterator cend() const { | ||||||
const_precision_iterator it(this); | ||||||
it.iterate_n_times(boost::real::real_algorithm::maximum_precision - 1); | ||||||
it.iterate_n_times(this->max_precision() - 1); | ||||||
return it; | ||||||
} | ||||||
|
||||||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -149,7 +149,7 @@ TEST_CASE("Iterator cend") { | |||||
|
||||||
SECTION("Iterate until the maximum set precision returns the end of the iterator") { | ||||||
|
||||||
for(int i = 0; i < 9; i++) { | ||||||
for(int i = 0; i < 14; i++) { | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
CHECK_FALSE( approximation_it == end_it ); | ||||||
++approximation_it; | ||||||
} | ||||||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is this max precision hardcoded with a 15? It should be the value of boost::real::real::maximum_precision which is the default max precision.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maximum_precision is an uninitialised variable currently and seems to take the value 10. Also, that hardcoded 15 is for algorithm numbers. I don't know what to use as its precision so I just chose 15. Please suggest default max precision for algorithm numbers which might have infinite precision. Or what show max_precision be initialised with for algorithm numbers?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
boost::real::real::maximum_precision and boost::real::real_algorithm::maximum_precision are global variables the user must set at the start of their code to specify the global maximum precision that is ever allowed. If you check the tests, you can notice in test/include/test_helpers.hpp in lines 9 and 10 that those variables are set in 10 and that is why they have that value (It is never hardcoded). With no exceptions, these variable is used as the max precision ever accepted and even for explicit numbers that have more digits than this maximum precision, they will throw a precision_exception.
The max precision is used to allow having some control in the algorithm memory and time complexities.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh no...
I never noticed the initialisations in test_helpers which has led to a lot of confusion for me as I couldn't figure out why the precision cap was at 10...
Now it seems like there wasn't any issue in the first place. The precision error I thought was a mistake was due to this max_precision of 10. And then the algorithm precision can just be kept as the max_precision set in test_helpers then.