Basic use of function “contains” in Boost ICL: Are some combinations of interval types and functions not implemented?

匿名 (未验证) 提交于 2019-12-03 08:50:26

问题:

I started to use Boost ICL and I stumbled upon very basic stuff. For example the function contains should return true or false depending if a given element is in the interval or not. However that works for [right,left]_open_intervals but not for [open,closed]_inteval (see example below).

This seems to be too obvious to be an oversight. I am using the library in the intended way?

For example (using gcc 4.8 or clang 3.3 and Boost 1.54):

#include <boost/concept_check.hpp> //needed to make this MWE work, boost icl should include it internally  #include<boost/icl/right_open_interval.hpp> #include<boost/icl/closed_interval.hpp> #include<boost/icl/open_interval.hpp> int main(){     boost::icl::right_open_interval<double> roi(6.,7.);     assert(boost::icl::contains(roi, 6.) == true);  //ok     assert(boost::icl::contains(roi, 6.) == false); //ok      boost::icl::closed_interval<double> oi(4.,5.); // or open_interval     assert(boost::icl::contains( oi, 4.) == false); //error: "candidate template ignored"     assert(boost::icl::contains( oi, 5.) == false); //error: "candidate template ignored" } 

Note: The above are called "static" intervals (because their bound properties are part of the type). Dynamic intervals work as expected.

回答1:

I would guess it comes down to the relative uselessness of floating point equality testing.

Have you ever tried to do assert(0.1 + 0.2 == 0.3)?

Try it. I'll wait.

In case you already know the answer, it'll be clear why a closed interval is not easy to implement correctly. Backgrounders:

Also, if you have two consecutive closed intervals [a,b][b,c]. in which interval does b belong?



标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!