Ignore:
Timestamp:
06/18/08 21:39:50 (17 years ago)
Author:
tbretz
Message:
*** empty log message ***
Location:
trunk/MagicSoft/Mars/mbase
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/MagicSoft/Mars/mbase/MMath.cc

    r8957 r8978  
    11/* ======================================================================== *\
    2 ! $Name: not supported by cvs2svn $:$Id: MMath.cc,v 1.38 2008-06-14 15:55:50 tbretz Exp $
     2! $Name: not supported by cvs2svn $:$Id: MMath.cc,v 1.39 2008-06-18 20:39:48 tbretz Exp $
    33! --------------------------------------------------------------------------
    44!
     
    811811    return 3;
    812812}
     813
     814// --------------------------------------------------------------------------
     815//
     816// Format a value and its error corresponding to the rules (note
     817// this won't work if the error is more then eight orders smaller than
     818// the value)
     819//
     820void MMath::Format(Double_t &v, Double_t &e)
     821{
     822    // Valid digits
     823    Int_t i = TMath::FloorNint(TMath::Log10(v))-TMath::FloorNint(TMath::Log10(e));
     824
     825    // Check if error starts with 1 or 2. In this case use one
     826    // more valid digit
     827    TString error = Form("%.0e", e);
     828    if (error[0]=='1' || error[0]=='2')
     829    {
     830        i++;
     831        error = Form("%.1e", e);
     832    }
     833
     834    const char *fmt = Form("%%.%de", i);
     835
     836    v = atof(Form(fmt, v));
     837    e = error.Atof();
     838}
  • trunk/MagicSoft/Mars/mbase/MMath.h

    r8585 r8978  
    11#ifndef MARS_MMath
    22#define MARS_MMath
     3
     4#ifndef _MATH_H
     5#include <math.h>  // Needed for darwin
     6#endif
    37
    48#ifndef ROOT_TMath
     
    6973    TArrayD LeastSqFitPowerLaw(Int_t n, Double_t *x, Double_t *y);
    7074
    71     inline Int_t ModF(Double_t dbl, Double_t &frac) { Double_t rc; frac = modf(dbl, &rc); return TMath::Nint(rc); }
     75    inline Int_t ModF(Double_t dbl, Double_t &frac) { Double_t rc; frac = ::modf(dbl, &rc); return TMath::Nint(rc); }
    7276
    73     inline Double_t Sqrt3(Double_t x) { return cbrt(x); }
     77    inline Double_t Sqrt3(Double_t x) { return ::cbrt(x); }
    7478
    7579    inline Double_t Sgn(Double_t d) { return d<0 ? -1 : 1; }
     80
     81    void Format(Double_t &v, Double_t &e);
    7682}
    7783
Note: See TracChangeset for help on using the changeset viewer.