Storing high-precision values in a TTree

I’d like to store a set of floating-point values in a TTree, without loss of precision. Unfortunately, double's do not offer enough precision, so I’m currently using boost's cpp_dec_float_100 “multiprecision” type.

For example, one of the values I wish to store is 0.42874828 which, when stored as type double is given the value 0.4287482799999999816265017216210253536701202392578125, but when stored as boost's cpp_dec_float_100 type retains the value and precision of 0.42874828.

I’ve spent some time looking over the TTree documentation and, while I’ve likely missed something obvious, it isn’t clear to me how I would go about storing boost's cpp_dec_float_100 type in a TTree (or perhaps there’s a better/ROOT way?).


Please read tips for efficient and successful posting and posting code

ROOT Version: Not Provided
Platform: Not Provided
Compiler: Not Provided


In principle, all “floating-point” formats are prone to (what you call it) “loss of precision”.

The double-precision floating-point format, with 53-bit significand precision, gives from 15 to 17 significant decimal digits precision (note: it depends on the actual value):

{
  double v = 42874828;
  printf("%.15g\n", v);
  printf("%.17g\n", v);
  v /= 100000000;
  printf("%.15g\n", v);
  printf("%.17g\n", v);
}

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.