Date: Jul 25, 2013 11:51 AM
Subject: Re: precision of floating number in matlab and c++
"someone" wrote in message <firstname.lastname@example.org>...
> "WK" wrote in message <email@example.com>...
> > "James Tursa" wrote in message <firstname.lastname@example.org>...
> > > "WK" wrote in message <email@example.com>...
> ... SNIP ...
> > I check the result, it gives the same sequence as matlab does (I only check up to the 4 decimal places). Well, it these two sequences are different, so how matlab generating that? and why they are different if both use double precision?
> You really need to check to more than 4 decimal places.
> You would probably get a SLIGHTLY different sequence if you used linspace instead of the colon operator or a for loop (as you did with C++), for example.
> Take a look at the at the references in the MATLAB FAQ:
> for a more detailed discussion of floating point numbers.
> Also, (and this is out of my comfort zone) as I recall the c/c++ specification for floating point precision is machine/complier independent. That is, it does not specify whether double precision is 16, 32, or 64 bits. It simply requires that:
> double precision >= single precision
> As I said, I may not be up to date on this topic, but that is my recollection.
The compiler I am using is running in 64bit linux system and it uses 64bits to for double precision. The MATLAB I am running is in 64bit windows 8 and also 64bit precision for double. But I am wondering it the floating point representation in matlab is of different standard. I try
it shows 0.3333333333333333100000000000000000000000000000000000000000000000000000000000000000000000000000000000
in c++, I try
cout << setprecision(100) << 1.0/3.0 << endl;