ROOT version:
6.40.02 and 6.32.12 (Initially found on 6.32.12 - verified to still be an issue with 6.40.02)
Platform:
Ubuntu 24.04
The built-in sqrt() function used by TTree::Scan (and presumably TTreeFormula)
appears to evaluate sqrt(abs(x)) rather than sqrt(x) for negative arguments.
Minimal reproducer:
void test_sqrt(){
// Reproduce sqrt of a negative number bug/feature when using TTree Scan
// Instead of producing a NaN, sqrt(x) as evaluated by TTreeFormula gives sqrt(|-x|)
// when x is negative. TMath:Sqrt(x) gives the correct behavior.
TTree t("t","t");
int dummy = 0;
t.Branch("dummy", &dummy, "dummy/I");
t.Fill();
cout << "buggy sqrt of negative number test" << endl;
t.Scan("sqrt(-4.0):TMath::Sqrt(-4.0)");
}
Output:
$ root -l
root [0] .x test_sqrt.C
buggy sqrt of negative number test
- Row * sqrt(-4.0 * TMath::Sq *
Expected output:
$ root -l
root [0] .x test_sqrt.C
buggy sqrt of negative number test
- Row * sqrt(-4.0 * TMath::Sq *
The same behaviour is observed for arbitrary negative expressions, e.g.
sqrt(-(4))
sqrt(0-4)
sqrt(-1*4)
all evaluate to 2.
The problem also appears when evaluating expressions involving tree variables using sqrt, e.g.
returns sqrt(abs(Spara1**2-13.69)) whenever the argument is negative.
TMath::Sqrt() behaves correctly.
thanks,
Graham
ROOT version:
6.40.02 and 6.32.12 (Initially found on 6.32.12 - verified to still be an issue with 6.40.02)
Platform:
Ubuntu 24.04
The built-in sqrt() function used by TTree::Scan (and presumably TTreeFormula)
appears to evaluate sqrt(abs(x)) rather than sqrt(x) for negative arguments.
Minimal reproducer:
void test_sqrt(){
// Reproduce sqrt of a negative number bug/feature when using TTree Scan
// Instead of producing a NaN, sqrt(x) as evaluated by TTreeFormula gives sqrt(|-x|)
// when x is negative. TMath:Sqrt(x) gives the correct behavior.
}
Output:
$ root -l
root [0] .x test_sqrt.C
buggy sqrt of negative number test
Expected output:
$ root -l
root [0] .x test_sqrt.C
buggy sqrt of negative number test
The same behaviour is observed for arbitrary negative expressions, e.g.
all evaluate to 2.
The problem also appears when evaluating expressions involving tree variables using sqrt, e.g.
returns sqrt(abs(Spara1**2-13.69)) whenever the argument is negative.
TMath::Sqrt() behaves correctly.
thanks,
Graham