Cannot get correct bin number

Dear experts,
I am wondering why the following gives incorrect bin number.

root [0]   float d[4] = {1.8, 2, 3 ,4}

root [1] TH1D h4("h4", "", 3, d)

root [2] h4.FindBin(1.8)

(int) 1

root [4]  float e[4] = {1.7, 2, 3 ,4}

root [5] TH1D h3("h3", "", 3, e)

root [6] h3.FindBin(1.7)

(int) 0

Seems it is a bug


ROOT Version: TH1D h4(“h4”, “”, 3, d)
Platform: Ubuntu 18
Compiler: gcc (Ubuntu 7.3.0-27ubuntu1~18.04) 7.3.0


Try with:

double d[4] = ...
double e[4] = ...

P.S. Google for “floating point rounding error”, “round-off error”, “floating point arithmetic precision”, and so on.

Thank you, it works.

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