# How to access tgraphasymmerrors x values

I have a really weird problem, perhaps due to my absolute newbieness to python. I have a TFile, which contains a TGraphAsymmErrors. If I try

``` for i in range(mygraph.GetN()): ye_x = mygraph.GetX()[i] print ye_x print ye_x == 0.2 print str(te_x) == "0.2" ```

I get (even if i force ye_x = float(mygraph.GetX()[i]))

``` ... 0.2 False True```

Could somebody please explain me this behaviour? What must I do in order to perform such a simple plain check on my graph’s x values?

Hi rene,

This looks like it is just standard computer floating point error. Your comparison is failing because the value is not exactly 0.2. The python tutorial has a pretty good overview of this issue:
http://docs.python.org/tutorial/floatingpoint.html
but it exists in most languages, as most rely on the computers built in floating point arithmetic, and so the same code shouldn’t even work in C++. Python actually hides this effect somewhat, but you can see it in CINT if you just type at the root prompt:

```root [0] 0.2 (const double)2.00000000000000011e-01 ```

The solution is generally to compare the absolute difference to see if it is less than some value:

``` for i in range(mygraph.GetN()): ye_x = mygraph.GetX()[i] print ye_x print abs(ye_x - 0.2) < 1e-10 print ye_x == 0.2 print str(te_x) == "0.2"```

Hi,

the representation should not be a problem if the value is actually set to 0.2, rather than just being very close to 0.2 (e.g. as the result of a calculation). Point being, the GetX() returns a double and the underlying type of a python float is C double.

For printing all the digits available to python, use repr(ye_x) rather than str(ye_x).

Cheers,
Wim