Main Page   Class Hierarchy   Data Structures   File List   Data Fields   Globals  

precision.C

Go to the documentation of this file.
00001 /*
00002  *  precision.C:  Set output precision for starlab programs.
00003  *
00004  *.............................................................................
00005  *    version 1:  Nov 1994   Steve McMillan
00006  *    version 2:  
00007  *.............................................................................
00008  *  non-local functions: 
00009  *    set_starlab_precision
00010  *.............................................................................
00011  */
00012 
00017 
00018 // Probably should be implemented as a class (like kira_options)...
00019 
00020 #include "stdinc.h"
00021 
00022 #ifndef TOOLBOX
00023 
00024 static int precision = -1;
00025 
00026 // Accessor:
00027 
00028 int get_starlab_precision() {return precision;}
00029 
00030 local void get_default_precision()
00031 {
00032     // Establish the default Starlab precision setting.
00033     // First try the environment, then use a default value.
00034 
00035     precision = -1;
00036 
00037     char* s = getenv("STARLAB_PRECISION");
00038 
00039     if (s) {
00040         int p = atoi(s);
00041         if (p > 0) precision = p;
00042     }
00043 
00044     if (precision < 0)
00045 
00046         // Note by J.M. 97-Jan-5:  changed 16 to 18,
00047         // to try to guarantee the correctness of the
00048         // last bit (not thoroughly tested).
00049 
00050         precision = 18;
00051 }
00052 
00053 int set_starlab_precision(ostream &s)
00054 {
00055     if (precision < 0) get_default_precision();
00056     return s.precision(precision);      // convenient to return the
00057                                         // old "precision" setting
00058 }
00059 
00060 int adjust_starlab_precision(int p)
00061 {
00062     if (p >= 0)
00063         precision = p;
00064     else
00065         get_default_precision();        // reread the environment
00066 
00067     return precision;
00068 }
00069 
00070 #else
00071 
00072 main(int argc, char** argv)
00073 {
00074     check_help();
00075     set_starlab_precision(cout);
00076     
00077     real x = sqrt(2.0);
00078     cout << "x = " << x << endl;
00079 }
00080 
00081 #endif

Generated at Sun Feb 24 09:57:11 2002 for STARLAB by doxygen1.2.6 written by Dimitri van Heesch, © 1997-2001