我有一个与这里可用的问题(和答案)有关的问题:
C++ Boost Interval and cos
我也在尝试使用区间算术来计算三角函数,而且我面临的问题与上述问题的作者提出的问题类似。我尝试使用上面链接的问题的答案,并产生了下面的代码。但是它不能编译。这是代码:
#include <boost/numeric/interval.hpp>
using namespace boost::numeric;
using namespace interval_lib;
typedef interval<double, policies<save_state<rounded_transc_std<double> >, checking_base<double> > > Interval;
int main()
{
Interval i1(1.0, 2.0);
Interval i2 = cos(i1);
return 0;
}
我收到的错误如下:
In file included from /usr/include/boost/numeric/interval/hw_rounding.hpp:15:0,
from /usr/include/boost/numeric/interval.hpp:18,
from interval_test.cpp:34:
/usr/include/boost/numeric/interval/rounded_arith.hpp: In instantiation of ‘T boost::numeric::interval_lib::rounded_arith_std<T, Rounding>::int_down(const T&) [with T = double; Rounding = boost::numeric::interval_lib::rounding_control<double>]’:
/usr/include/boost/numeric/interval/arith2.hpp:40:49: required from ‘boost::numeric::interval<T, Policies> boost::numeric::fmod(const boost::numeric::interval<T, Policies>&, const boost::numeric::interval<T, Policies>&) [with T = double; Policies = boost::numeric::interval_lib::policies<boost::numeric::interval_lib::detal ::save_state_unprotected<boost::numeric::interval_lib::rounded_transc_std <double> >, boost::numeric::interval_lib::checking_base<double> >]’
/usr/include/boost/numeric/interval/transc.hpp:62:32: required from ‘boost::numeric::interval<T, Policies> boost::numeric::cos(const boost::numeric::interval<T, Policies>&) [with T = double; Policies = boost::numeric::interval_lib::policies<boost::numeric::interval_lib::save_ state<boost::numeric::interval_lib::rounded_transc_std<double> >, boost::numeric::interval_lib::checking_base<double> >]’
interval_test.cpp:44:25: required from here
/usr/include/boost/numeric/interval/rounded_arith.hpp:71:61: error: ‘to_int’ was not declared in this scope, and no declarations were found by argument-dependent lookup at the point of instantiation [-fpermissive]
T int_down(const T& x) { this->downward(); return to_int(x); }
^
/usr/include/boost/numeric/interval/rounded_arith.hpp:71:61: note: declarations in dependent base ‘boost::numeric::interval_lib::detail::c99_rounding_control’ are not found by unqualified lookup
/usr/include/boost/numeric/interval/rounded_arith.hpp:71:61: note: use ‘this->to_int’ instead
我正在使用boost 1.54.0和gcc 4.8.4。
你知道我在做什么错吗?
非常感谢你的帮助。
最佳答案
此问题已在2014/2015年修复:请参见https://github.com/boostorg/interval/pull/1
Boost 1.58中提供了此修复程序,因此您必须将Boost版本至少升级到1.58。
关于c++ - boost 区间算术和三角函数,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/39355906/