-
Notifications
You must be signed in to change notification settings - Fork 51
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
Interval <-> char* conversion #190
base: master
Are you sure you want to change the base?
Conversation
(now, build and tests OK on this branch) |
Jordan has pointed out that the |
Hi Simon,
|
Hi Gilles, I updated the code, removing the new functions from Interval(const std::string& s);
std::ostream& operator<<(std::ostream& os, const Interval& x);
std::string str(int precision = 6) const; The So now, IBEX has its own convention for interval string conversions. I used the Filib convention. Other improvements can be provided before the merge. You tell me. Simon |
That is perfect like this, thanks for following my suggestion; I am going to merge the pull request.
This would allow simple usage like
Gilles |
Ok for the cast, but we will lose the precision parameter. No big deal since we can still use the ostream cast with inline std::string operator+(const std::string& s, const Interval& x);
inline std::string operator+(const Interval& x, const std::string& s); In order to allow: string s = "my interval is" + x; Otherwise, a cast Simon |
Yes, you are right. Now I realize that it was maybe not a good suggestion... :-/ |
Hi Gilles, |
Dear Simon, OK... so I guess that the string cast operator will depend now on the default precision of stringstream objects. It makes sense. I have to say that building interval from strings is actually more complicated because of the decimal representation of floating point numbers. For example, if one writes "[0.1,0.1]", since 0.1 is actually not binary representable, using atof(0.1) will result in an approximate value of 0.1 that is either slightly smaller or greater than 0.1. In any case, the resulting interval will lose the value 0.1. So the conversion is unsafe. I remember that the string representation of intervals has been discussed in the IEEE1788 standard. Maybe you should have a look. We can live with an unsafe conversion for the moment. But, at least, we have to write a big "warning" in the documentation. Other remark, I think you did not take into account intervals with infinite bounds like "[3,oo]". The symbol "oo" (with potentially a sign +/-) is valid in Minibex so it should be as well in C++. |
Note: the same problem goes with minibex |
Add a function to convert an Interval object to a C string (char*) and its reciprocal feature:
This comes with unit tests.
Will be used for robotics purposes but should be implemented inside ibex-lib.