簡體   English   中英

Boost.Units 如何得出這種不精確的轉換結果?

[英]How does Boost.Units come up with this imprecise result of conversion?

考慮以下代碼:

#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后被截斷。 但正如我grep PED我的/usr/include/ ,我才發現,在這個定義不確切/usr/include/python2.7/Imaging.h ,它看起來相當無關。 所有其他人都指定了更多的十進制數字。

所以,我的問題是:Boost 是如何得出這個結果的?

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 返回您看到的值。 這當然看起來不太對勁,但唉,這似乎是事實。

更新:我發現了這個問題的錯誤報告: https : //svn.boost.org/trac/boost/ticket/6893

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM