Skip to Content.
Sympa Menu

sphenix-software-l - [Sphenix-software-l] TMath rant

sphenix-software-l AT lists.bnl.gov

Subject: sPHENIX discussion of software

List archive

Chronological Thread  
  • From: pinkenburg <pinkenburg AT bnl.gov>
  • To: "sphenix-software-l AT lists.bnl.gov" <sphenix-software-l AT lists.bnl.gov>
  • Subject: [Sphenix-software-l] TMath rant
  • Date: Mon, 20 Aug 2018 16:53:44 -0400

Hi folks,

really - please stay away from TMath. I find that it is being used even for basic math functions. Why shouldn't it be used?
Have a look at TMath::ACos(double x), it returns the acos of x right?

WRONG

here is the TMath::ACos code:

inline
Double_t TMath::ACos(Double_t x)
{
  if (x < -1.) return TMath::Pi();
  if (x > 1.) return 0;
  return acos(x);
}

If you call it with an invalid value of x (outside +/-1) it returns a valid value while the function from the glibc returns NaN (which then propagates through the rest of your calculation making it very obvious in the result that you have a problem).

Good luck finding such a problem when using TMath which is full of this kind of scary stuff. Do yourself (and sPHENIX) a favor and don't use TMath. If the use of TMath is unavoidable - please have a look what it is really doing before.

Chris

-- 
*************************************************************

Christopher H. Pinkenburg	;    pinkenburg AT bnl.gov
				;    http://www.phenix.bnl.gov/~pinkenbu

Brookhaven National Laboratory	;    phone: (631) 344-5692
Physics Department Bldg 510 C	;    fax:   (631) 344-3253
Upton, NY 11973-5000

*************************************************************


  • [Sphenix-software-l] TMath rant, pinkenburg, 08/20/2018

Archive powered by MHonArc 2.6.24.

Top of Page