Re: Numerical accuracy of C++ and Fortran programs on 32 bit machines
- From: "Thomas Smid" <thomas.smid@xxxxxxxxx>
- Date: 13 Jun 2005 11:03:37 -0700
osmium wrote:
> "Thomas Smid" writes:
>
> > For C++:
> > _____________________________
> > #include <iostream.h>
> > #include <fstream.h>
> > #include <stdlib.h>
> > #include <math.h>
> >
> >
> > void main() {
> > ofstream outfile ("out.txt");
> > double x,y,z;
> > x=4.0E0;
> > y=3.0E0;
> > z=x/y;
> >
> > outfile <<z ;
> > system("PAUSE");
> > return 0;
> > }
> > _________________________
> >
> > This program prints out 1.33333 for z (which is even only 6 significant
> > digits) when compiled end executed with Dev-C++, even though all
> > variables are declared double (and as far as I am aware this compiler
> > supports only double precision anyway; there are for instance no Float
> > versions of the mathematical functions in the library)
>
> You are seeing the constraints imposed by the printing process. There is a
> variable called precision and the default value is what you are using. Look
> for something called set precision, IIRC there are both function and
> manipulator forms of the desired thingy.
Thanks a lot. When I use
outfile << setprecision (20) << z ;
it prints indeed all siginificant digits.
I still had to use
#include <iomanip.h>
additionally in the header as otherwise it would assume that
setprecision is a variable.
This still leaves the discrepancy in the Fortran example though where
it is obviously not an I/O matter.
Thomas
.
- Follow-Ups:
- Re : Numerical accuracy of C++ and Fortran programs on 32 bit machines
- From: Jean-Claude Arbaut
- Re: Numerical accuracy of C++ and Fortran programs on 32 bit machines
- From: Duane Bozarth
- Re: Numerical accuracy of C++ and Fortran programs on 32 bit machines
- From: Duane Bozarth
- Re : Numerical accuracy of C++ and Fortran programs on 32 bit machines
- References:
- Numerical accuracy of C++ and Fortran programs on 32 bit machines
- From: Thomas Smid
- Re: Numerical accuracy of C++ and Fortran programs on 32 bit machines
- From: Duane Bozarth
- Re: Numerical accuracy of C++ and Fortran programs on 32 bit machines
- From: Thomas Smid
- Numerical accuracy of C++ and Fortran programs on 32 bit machines
- Prev by Date: Re: newbie
- Next by Date: ypSlideOutMenus suggestion needed
- Previous by thread: Re: Numerical accuracy of C++ and Fortran programs on 32 bit machines
- Next by thread: Re: Numerical accuracy of C++ and Fortran programs on 32 bit machines
- Index(es):
Relevant Pages
|
Loading