考虑以下代码:
#include <boost/units/io.hpp>
#include <boost/units/systems/si/plane_angle.hpp>
#include <boost/units/systems/angle/degrees.hpp>
#include <iostream>
#include <cmath>
#include <limits>
int main()
{
using namespace boost::units;
std::cout.precision(std::numeric_limits<double>::digits10);
std::cout << "Everyone knows that 180 deg = " << std::acos(-1.) << " rad\n";
std::cout << "Boost thinks that 180 deg = "
<< quantity<si::plane_angle,double>(180.*degree::degree) << "\n";
}
我得到以下输出:
Everyone knows that 180 deg = 3.14159265358979 rad
Boost thinks that 180 deg = 3.14159265359 rad
显然,Boost.Units 手动定义的 M_PI 精度非常低,因为它在第 12 个之后被截断decimal地方。但正如我grep
ped my /usr/include/
,我只在中找到了这个不精确的定义/usr/include/python2.7/Imaging.h
,这看起来完全无关。所有其他的都指定了更多的小数位数。
那么,我的问题是:Boost是如何得出这个结果的?
From boost/units/base_units/angle/degree.hpp
:
BOOST_UNITS_DEFINE_BASE_UNIT_WITH_CONVERSIONS(angle,degree,"degree","deg",6.28318530718/360.,boost::units::angle::radian_base_unit,-101);
将 6.28318530718 除以 2 返回您看到的值。这看起来当然不太正确,但可惜,情况似乎确实如此。
Update:我发现了这个问题的错误报告:https://svn.boost.org/trac/boost/ticket/6893
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)