boost::numeric::interval constructor seems not creating an interval enclosing its arguments
Nobody has claimed this yet.
Assessment
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Newbie friendliness
- 35/100
Research direction
Start by reproducing the examples with boost/numeric/interval.hpp, Boost 1.85.0, and -frounding-math, then compare the constructor and += behavior with the interval documentation. Determine whether the observed bounds match the documented rounding guarantees and identify what existing tests cover these cases. Done means the behavior is explained and any required implementation or documentation change is covered by tests.
Written by the indexing model from the issue text.
Description
In the document of boost interval https://www.boost.org/doc/libs/1_86_0/libs/numeric/interval/doc/interval.htm#interval
If the interval constructor has only one argument, "The constructors create an interval enclosing their arguments."
But in the following code, seems not working like this, it just sets interval's upper and lower bounds as the same value of my input. This is NOT what we expect for interval arithmetic, since the input may not be precisely stored in a computer.
#include <iostream>
#include <boost/numeric/interval.hpp>
using namespace std;
int main() {
cout << setprecision(20);
boost::numeric::interval<double> I = boost::numeric::interval<double>(0.1);
cout << I.upper() << endl; // print: 0.10000000000000000555
cout << I.lower() << endl; // print: 0.10000000000000000555
}
another strange thing is when I add a double number, sometimes it gives the desired bound, but sometimes NOT! See below, adding 0.1 to the interval and adding 1.1 to the interval gives different type of the result. adding 1.1 gives the desired result.
#include <iostream>
#include <boost/numeric/interval.hpp>
using namespace std;
int main() {
cout << setprecision(20);
boost::numeric::interval<double> I = boost::numeric::interval<double>(0.1);
I += 0.1 // add 0.1
cout << I.upper() << endl; // print: 0.2000000000000000111
cout << I.lower() << endl; // print: 0.2000000000000000111
}
#include <iostream>
#include <boost/numeric/interval.hpp>
using namespace std;
int main() {
cout << setprecision(20);
boost::numeric::interval<double> I = boost::numeric::interval<double>(0.1);
I += 1.1 // add 1.1
cout << I.upper() << endl; // print: 1.2000000000000001776
cout << I.lower() << endl; // print: 1.1999999999999999556
}
When compiling I add -frounding-math, and the boost version is v1.85.0.
- Dominant language
- C++
- Stars
- 31
- Forks
- 49
- Avg merge
- 2d 2h
- Merged PRs (30d)
- 3
Getting set up
This project ships no dev container, Dockerfile or contributing guide, so setting up is up to you: start from its README, and see our first-contribution guide for the general steps.
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from boostorg/interval
-
Difficulty 4/5 3-5 days Newbie friendliness 35/100
-
Difficulty 4/5 3-5 days Newbie friendliness 35/100
-
Difficulty 5/5 Over a week Newbie friendliness 10/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 45/100
-
Difficulty 5/5 Over a week Newbie friendliness 25/100
All issues in boostorg/interval
Similar issues
-
feature request
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
Maintainers usually reply within 2 days
-
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
Maintainers usually reply within 1 day
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
gavinlouuu-kpt/mib-studio-qt#517 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
Maintainers usually reply within 1 day
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 73/100
EchoTools/nevr-runtime#116 ·
Maintainers usually reply within 1 day