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: fmingu (fmingu_at_[hidden])
Date: 2010-03-28 21:02:29


ÔÚ2010-03-29 08:28:13£¬"Steven Watanabe" <watanabesj_at_[hidden]> дµÀ£º
>AMDG
>
>fmingu wrote:
>> 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 same question occurred in random number generation in boost random library.
>>
>
>Use std::setprecision to print more digits.
>
>In Christ,
>Steven Watanabe
>
I rewrote the program following your advice but
std::cout << "The matrices are: B=\n" << std::setprecision(5)<<B<<"\n";
do not show any changes while the code:
    std::cout << "The result is " << std::setprecision(10)<<1.0/3.0 <<"\n";
worked well.
How can I do now?
Thanks a lot.



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