RE: [ROOT] How can I choose the accuracy of numbers ?

From: Christian Holm Christensen (cholm@nbi.dk)
Date: Wed May 26 2004 - 22:55:24 MEST


Hi Luis,

On Wed, 2004-05-26 at 20:33, Luis March Ruiz wrote: 
>   This mailing list is incredible !!!
> 
>   Thanks very much to both (your replies were very fast),
While Valeri is correct, and you can use the stdio library like this, I
would like to discourage the use of stdio in C++, and promote use of the
iostream library.  Using iostream and stdio together does have some
pitfalls and the standard gives very few quaranties.   Further, using as
many C++ constructs (instead of similar C constructs) helps you learn
the language and philosophy better.  

>   I finally got it making 
> 
>   fprintf(foutput," %s    %8.4lf    %8.4lf      %8.4lf       %8.4lf      
> %8.4lf \n",histo,p0[i],e0[i],Chi2_offset,Chi_2_red,Kolmog_comp[i]);
> 
>   as Valeri said me, but between "%" and "lf" (8 is the total width and 4 
> is the decimal digits that I chose).
I would do 

  #include <iostream>
  #include <iomanip>

  ...

  cout << histo << "   " 
<< setw(8) << setprecision(4) << p0[i] 
<< setw(8) << setprecision(4) << e0[i] 
<< setw(8) << setprecision(4) << chi2_offset 
<< setw(8) << setprecision(4) << chi2_red 
<< setw(8) << setprecision(4) << Kolmog_comp[i] 
<< endl;

>   Stilianos, #include <iomanip> will help me also, because I will use it 
> soon.

Note, that cout, setprecision, setw, endl are all members of the
namespace std, so you may need to qualify the names, or do 

  using namespace std; 
 
Also note the std::stringstream class. Instead of doing 

  sscanf(foo, "%lf %lf", &x, &y);

One would do 

  std::stringstream foo_stream(foo);
  foo >> x >> y;


>   Best regards,
> 
>                                                    Luis
> 
> 
> > Check "Using printf() for Output in C Programs (PDF)"
> > 
> > http://www.wvutech.edu/mclark/CS%20Eng%20I/Using%20printf2.pdf

Why not the ISO/IEC C++ Programming Language Standard :-)

Yours,

-- 
 ___  |  Christian Holm Christensen 
  |_| |	 -------------------------------------------------------------
    | |	 Address: Sankt Hansgade 23, 1. th.  Phone:  (+45) 35 35 96 91
     _|	          DK-2200 Copenhagen N       Cell:   (+45) 24 61 85 91
    _|	          Denmark                    Office: (+45) 353  25 404
 ____|	 Email:   cholm@nbi.dk               Web:    www.nbi.dk/~cholm
 | |



This archive was generated by hypermail 2b29 : Sun Jan 02 2005 - 05:50:08 MET