[英]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。:)。 nan
是sqrt(-x)
最合適的答案。 你可以sqrt
std::complex<T>
sqrt
。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.