This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
possible problem with long double
- From: Vivaldo <vlcampo at iccmp dot org>
- To: gcc at gcc dot gnu dot org
- Date: Tue, 01 Nov 2005 10:26:57 -0200
- Subject: possible problem with long double
Dear Sir,
I have found a difficult do work with long double. I have written a
simple test code and compiled it with gcc 4.0.0. The code was the following
#include <cmath>
#include <iostream>
using namespace std;
main(){
long double x,y,a;
x = 1.000000000000001; //(1 at 15th decimal place)
y = 1.000000000000002; //(idem)
a = y - x;
cout.precision(30);
cout << a << endl;
}
Surprinsingly, the output written in the screen was not
1.0000....e-15
with 19 correct decimal places. Instead the result was
8.88178419700125232338905334473e-16
with error at the 16-th place!
How should I proceed to have the precision of 19 significative digits?
Thanks.
Vivaldo L. Campo.
Physicist - ICCMP - Brasilia - Brazil.