Boost logo

Boost Users :

Subject: Re: [Boost-users] A question on the preciseness of the double used in MTL. Can anyone with kindness help me?
From: Paul A. Bristow (pbristow_at_[hidden])
Date: 2010-03-29 05:06:28


From: boost-users-bounces_at_[hidden] [mailto:boost-users-bounces_at_[hidden]] On Behalf Of fmingu
Sent: Monday, March 29, 2010 1:12 AM
To: boost-users
Subject: [Boost-users] A question on the preciseness of the double used in MTL. Can anyone with kindness help me?

I am using MTL(Matrix Template Library) for Matrix computing in Dev-C++ 4.9.8.0 and updated the gcc version from 3.2 to
4.4.1 by installing tdm-mingw-1.908.0-4.4.1-2 and the boost version is 1.37.0. The system is Windows xp The sample code
is :
 
#include <boost/numeric/mtl/mtl.hpp>
 
#include "boost/random/normal_distribution.hpp"
#include <boost/random.hpp>
#include <boost/random/uniform_real.hpp>
 
 
int main(int argc, char* argv[])
{
    using namespace mtl; using namespace mtl::matrix;
    
    const unsigned n= 5;
    dense2D<double> A(n, n), B(n, n);
    morton_dense<double, doppled_64_row_mask> C(n, n), D(n, n);
    
    dense2D<double> F(n, n), E(n, n);
    hessian_setup(A, 3.0); hessian_setup(B, 1.0);
    hessian_setup(C, 2.0); hessian_setup(D, 11.0);
    B(1,1)=9.9999;
    ..........................
        std::cout << "The matrices are: B=\n" << B <<"\n";
        std::cout << "The result is " <<1.0/3.0 <<"\n";
    …………………….
    But the result is shown that B(1,1) is 10, and 1.0/3.0 is 0.33.

> How can I get the highest precision of the type double and dense2D<double> for scientific computation?

The highest significant precision for the floating point you are using can be got using
   your_stream.precision(2 + std::numeric_limits<double>::digits * 3010/10000);
For the usual 64 bit doubles this is equivalent to
cout << setprecision(17) ...
This should every digit that might possibly be significant.
Using C++0X you should be able to use std::numeric_limits<double>::maxdigits10()
This is about 2 digits more than the std::numeric_limits<double>::digits10() function which is the maximum number of
digits guaranteed accurate decimal digits (for 64 bit double it is 15 decimal digits).

HTH

Paul

---
Paul A. Bristow
Prizet Farmhouse
Kendal, UK   LA8 8AB
+44 1539 561830, mobile +44 7714330204
pbristow_at_[hidden]

Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net