# Truncation of large numbers using TTree query

**URL:** <https://root-forum.cern.ch/t/truncation-of-large-numbers-using-ttree-query/33110>\
**Category:** Newbie\
**Created:** [March 11, 2019, 5:27pm UTC](https://root-forum.cern.ch/t/truncation-of-large-numbers-using-ttree-query/33110 "2019-03-11T17:27:13Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![rkessler](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/r/ecd19e/32.png) [@rkessler](https://root-forum.cern.ch/u/rkessler)\
**Post date:** [March 11, 2019, 5:27pm UTC](https://root-forum.cern.ch/t/truncation-of-large-numbers-using-ttree-query/33110/1 "2019-03-11T17:27:14Z")

</div>

I have been using ROOT Trees for years to store and read tables from analysis of supernova data. However, I recently noticed a problem storing Galaxy ID, which can be very large. I tried both double and ‘long long int’. In both cases I can Scan the values back with interactive root, as long as I specify something like “precision=20” as an option. Within the C code, however, the query option always truncates very large numbers to just 4 digits of precision. For ID=131336659, for example, it reads back a string value 1.313e+11. I searched online for tricks, but couldn’t find anything. Below is the relevant code snippet. “scanString” is a colon-separated list of variables to read. The optString seems to be ignored, even if I fill it with garbage characters.

TREE\_INFO\_READ.SQL\_Result =  
TREE\_INFO\_READ.tree-\>Query(scanString, “”, optString,  
NROW\_READ, IROW\_START);

Nfield = TREE\_INFO\_READ.SQL\_Result-\>GetFieldCount();  
Nrow = TREE\_INFO\_READ.SQL\_Result-\>GetRowCount();

while( (TREE\_INFO\_READ.SQL\_Row =  
(TSQLRow \*)TREE\_INFO\_READ.SQL\_Result-\>Next()) ) {

```
for (i=0; i < Nfield; i++) { // ivar_read loop                             
  sprintf(tmpString,"%s ", TREE_INFO_READ.SQL_Row->GetField(i));
```

---

<div class="post-metadata">

**Author:** ![bellenot](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/bellenot/32/29217_2.png) [@bellenot](https://root-forum.cern.ch/u/bellenot)\
**Post date:** [March 11, 2019, 9:42pm UTC](https://root-forum.cern.ch/t/truncation-of-large-numbers-using-ttree-query/33110/2 "2019-03-11T21:42:43Z")

</div>

Unsigned long 64 bit has a range from 0 to 18,446,744,073,709,551,615. Isn’t it enough?

---

<div class="post-metadata">

**Author:** ![rkessler](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/r/ecd19e/32.png) [@rkessler](https://root-forum.cern.ch/u/rkessler)\
**Post date:** [March 11, 2019, 11:08pm UTC](https://root-forum.cern.ch/t/truncation-of-large-numbers-using-ttree-query/33110/3 "2019-03-11T23:08:29Z")

</div>

The 64 bit range is fine, but the problem is when reading back with TTree query, it only returns 4 digits and an exponent. The question is how to read back all of the digits, since we need all the digits for a Galaxy identifier.

---

<div class="post-metadata">

**Author:** ![Wile\_E\_Coyote](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/wile_e_coyote/32/12417_2.png) [@Wile\_E\_Coyote](https://root-forum.cern.ch/u/Wile_E_Coyote)\
**Post date:** [March 12, 2019, 7:36am UTC](https://root-forum.cern.ch/t/truncation-of-large-numbers-using-ttree-query/33110/4 "2019-03-12T07:36:16Z")

</div>

Well, I guess the problem is that when you print it then the default output format is what you see (i.e. internally it has the full precision).

---

<div class="post-metadata">

**Author:** ![rkessler](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/r/ecd19e/32.png) [@rkessler](https://root-forum.cern.ch/u/rkessler)\
**Post date:** [March 12, 2019, 11:51am UTC](https://root-forum.cern.ch/t/truncation-of-large-numbers-using-ttree-query/33110/5 "2019-03-12T11:51:58Z")

</div>

Correct, internally it has the full precision, and the question is how to extract the values with full precision.
