Skip to content

Commit 4c1ed69

Browse files
committed
[tree] Fix long64 tree index losing precision on 64-bit long double platforms
The conditional `long64major ? GetLong64() : GetAndRangeCheck()` mixes Long64_t and LongDouble_t, so the exact value was promoted through long double regardless of branch. This rounded large values where long double is 64-bit (macOS arm64, Windows), making roottest-root-tree-index-indexl64 fail there while passing on Linux. Assign via if/else instead. 🤖 Done with the help of [Claude Code](https://claude.com/claude-code) (Claude Opus 4.8)
1 parent 0a8f816 commit 4c1ed69

1 file changed

Lines changed: 14 additions & 2 deletions

File tree

tree/treeplayer/src/TTreeIndex.cxx

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -211,8 +211,20 @@ TTreeIndex::TTreeIndex(const TTree *T, const char *majorname, const char *minorn
211211
auto GetLong64 = [this](bool isMajor) {
212212
return (isMajor ? fMajorFormula : fMinorFormula)->EvalInstance<Long64_t>();
213213
};
214-
tmp_major[i] = long64major ? GetLong64(true) : GetAndRangeCheck(true, i);
215-
tmp_minor[i] = long64minor ? GetLong64(false) : GetAndRangeCheck(false, i);
214+
// Note: assign in separate statements rather than using a ternary expression.
215+
// In `long64major ? GetLong64(...) : GetAndRangeCheck(...)`, the two branches have
216+
// types Long64_t and LongDouble_t, so the whole expression is promoted to their
217+
// common type `long double` *regardless of the branch taken*. On platforms where
218+
// `sizeof(long double) == sizeof(double)` (macOS arm64, Windows) this silently
219+
// rounds the exact Long64_t value, defeating the purpose of the long64 flag.
220+
if (long64major)
221+
tmp_major[i] = GetLong64(true);
222+
else
223+
tmp_major[i] = GetAndRangeCheck(true, i);
224+
if (long64minor)
225+
tmp_minor[i] = GetLong64(false);
226+
else
227+
tmp_minor[i] = GetAndRangeCheck(false, i);
216228
}
217229
fIndex = new Long64_t[fN];
218230
for(i = 0; i < fN; i++) { fIndex[i] = i; }

0 commit comments

Comments
 (0)