Re: Power function in TMath

From: Benjamin Bannier <benjamin.bannier_at_stonybrook.edu>
Date: Tue, 20 Jul 2010 15:45:42 -0400


Hi Alexander,

> According to this ATLAS recommendation
>
> https://twiki.cern.ch/twiki/bin/view/Atlas/CalculatingIntegerPowers
>
> one should always use std::pow() for these purposes (#include
> <cmath>), because of a factor 10 in performance gain.

Looking at cint/cint/lib/stdstrct/stdcxxfunc.h it appears that CINT already does what the documentation suggests: #include <cmath>, and map pow to std::pow with a using directive. These are defined there:

    float pow (float, float);
    float pow (float, int);

> For this reason I propose the implementation of a function
>
> Double_t TMath::Power(Double_t, Int_t)
>
> which simply encapsulates
>
> double std::pow( double, int );
>
> or
>
> long double std::pow( long double, int );
>
> from the cmath module of the C++ standard library.

So if inside a ROOT macro you say pow(2, 2) or pow(2,2.) you should get what you want (this doesn't even require you to include cmath since CINT appears to already know about it).

Not that using a ROOT macro probably won't give you the performance boost seen by in that test since you don't have the full set of optimizaitons available -- and if you would compile your code with ACLiC or directly you could just use std::pow from cmath yourself.

Benjamin

-- 
“Eighty percent of success is showing up.” – Woody Allen

Received on Tue Jul 20 2010 - 21:45:53 CEST

This archive was generated by hypermail 2.2.0 : Wed Jul 21 2010 - 23:50:02 CEST