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

Viewed 111

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

#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

The result while in release mode is 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.

1 Answers
Related