ROOT Epiphany of the Day

In ROOT, TMath::Pi is a function, not a constant. Where any sane group of person would surely write:

const Double_t Pi = 3.14159265358979323846;

The authors of ROOT choose instead to write:

Double_t Pi()
{ return 3.14159265358979323846; }

This form has no advantages that I can envision, and my testing shows that version 5.18, at least, of CINT is not smart enough to optimize away the pointless function call, making using the Pi() function measurably slower than using a a constant. The best part, and what got me, is that if you mistakenly assume that Pi must be a constant and use it that way, you'll end up doing math with the function address, which explains why my plots were all totally screwed up. And up through the latest versions of ROOT, they do this for every constant in their math namespace.

No Comments

Comment on this post