c++ - boost 区间算术和三角函数

标签 c++ math boost intervals trigonometry

我有一个问题与此处提供的问题(和答案)相关: 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/

相关文章:

c++ - 编译器无法推断返回类型?

java - 为什么 24 * 60 * 60 * 1000 * 1000 除以 24 * 60 * 60 * 1000 在 Java 中不等于 1000?

C++11 如何代理只有名称和父类的类函数?

c++ - 在 Boost::bimap 中使用指针

c++ - 如何迭代boost graph以获取顶点的传入和传出边缘?

c++ - 成员函数指针的类型推导

c++ - C++11 condition_variables 可以用于同步进程吗?

c++ - 事件调度器的设计

c - 如何编写一个 C 程序来检查一个点是否位于给定其对角线之一的端点的正方形内

c - 三角参数约简(约简模 2π)