繁体   English   中英

为什么boost数值库通过调试或发布模式给出不同的结果?

[英]Why does boost numeric library give different results by using debug or release mode?

当我使用调试模式或释放模式时,我遇到了我的代码给我不同结果的现象。 我把问题解决了下面的代码。 我正在使用Microsoft Visual Studio Professional 2013和自由增强1.62

#include "stdafx.h"
#include <iostream>
#include <math.h>

#include <boost/numeric/interval.hpp>
#include <boost/numeric/interval/rounded_arith.hpp>

using namespace std;
using namespace boost::numeric::interval_lib;
using namespace boost::numeric;

typedef interval<double, policies<save_state<rounded_transc_std<double> >,
checking_base<double> > > Interval;

int _tmain(int argc, _TCHAR* argv[])
{   
    Interval result = (Interval(3.15, 4.6) - Interval(-0.6, 2.1))*sqrt(Interval(2, 2) + Interval(-2, -2)*Interval(10.022631612535406, 10.031726559552226));
    cout << "result: " << result.lower() << " " << result.upper();

    return 0;
}

在调试模式下的结果是1.#QNAN 1.#QNAN

在释放模式下的结果是0 0

我想知道导致此问题的原因以及如何解决此问题。 如果我不能依赖结果,这会导致我的项目出现严重问题。

负数的sqrt是一个艰难的命题。 问题是Interval(-2, -2) VisualStudio的神奇之处还在于产生0,0。:)。 nansqrt(-x)最合适的答案。 你可以sqrt std::complex<T> sqrt

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM