简体   繁体   English

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

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

I've encountered the phenomena that my code gives me different results when i use debug mode or release mode. 当我使用调试模式或释放模式时,我遇到了我的代码给我不同结果的现象。 I've stripped the problem down to the code below. 我把问题解决了下面的代码。 I am using Microsoft Visual Studio Professional 2013 and the libeary boost 1.62 我正在使用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;
}

The result while in debug mode is 1.#QNAN 1.#QNAN 在调试模式下的结果是1.#QNAN 1.#QNAN

The result while in release mode is 0 0 在释放模式下的结果是0 0

I would like to know what causes this problem and how to fix this. 我想知道导致此问题的原因以及如何解决此问题。 Since this causes serious problems in my project if I cannot rely on the results. 如果我不能依赖结果,这会导致我的项目出现严重问题。

sqrt of a negative number is a tough proposition. 负数的sqrt是一个艰难的命题。 The problem is Interval(-2, -2) . 问题是Interval(-2, -2) It remains the magic of VisualStudio to produce 0, 0. :). VisualStudio的神奇之处还在于产生0,0。:)。 nan is the most appropriate answer to sqrt(-x) . nansqrt(-x)最合适的答案。 you may sqrt of std::complex<T> . 你可以sqrt std::complex<T> sqrt

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

相关问题 在调试模式下使用boost libs的发行版 - using the release version of boost libs in debug mode 为什么使用 __LINE__ 的这段代码在 MSVC 下可以在 Release 模式下编译,但不能在 Debug 模式下编译? - Why does this code using __LINE__ compile under MSVC in Release mode, but not in Debug mode? 在发布/调试模式下,Haar级联的结果不同 - Different results with Haar cascade when in release/debug mode Debug和Release之间的结果不同 - Different results between Debug and Release 调试和发布模式中的不同结果 - Different Results in Debug and Release Modes 使用Boost库检查CRC效果不理想 - Checking CRC using boost library does not give satisfactory result 在调试或发布模式下使用DLL? - Using DLL in debug or release mode? 为什么这个计算在boost :: thread和std :: thread中给出不同的结果? - Why does this calculation give different result in boost::thread and std::thread? 为什么Release / Debug对std :: min有不同的结果? - Why does Release/Debug have a different result for std::min? Visual Studio在发布模式下找不到boost包含文件(在调试中工作) - Visual Studio not finding boost include files in release mode (works in debug)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM