How to skip nan numbers in txt file

I have a txt file. It contains efficiency values for proton.
Some of the values are “nan”

(1). I need to know how to get rid of nan bins? Once I try to calculate the following “sigma_real”, this nan values bothers me.

for(int ith=0;ith < nth;ith++){
     for(int ip=0; ip < np;ip++){
sigma_real= pow(derr_proton[ith][ip]/data_proton[ith][ip],2)+ pow(serr_proton[ith][ip]/simu_proton[ith][ip],2));


Thank You

CD_efficiency_value.hpp (1.7 KB)

After you calculate “sigma_real”, try to add:
if (!TMath::Finite(sigma_real)) continue;

Thank you,Wile.
I have problem with reading value “nan”. I can replace it as “inf” or “0”.
But is there a way to represent nan value that readable from txt file?

/w/hallb-scshelf2102/dil/AnalysisRoot/RunRoot/cross_section/CD_efficiency_value.h:89:6: error: *cannot initialize an array element of type ‘const double’ with an lvalue of type 'double (const char ) throw()’

{nan, 0.808456, 0.651457, 0.591461, 0.471055, 0.371285},

No, Nan, means “not a number”. You cannot read them as such from a txt file. You always should avoid generating Nan, that’s a bug in you code if it does that… Your program should be protected against that.

In your C++ code, you can use TMath::QuietNaN() and / or TMath::SignalingNaN() “constants”.

Hello Wile,

This doesn’t work on me.
TMath::QuietNaN() and / or TMath::SignalingNaN()

 if (TMath::QuiteNaN())    weight_pim=(simu_pim[ith_pim][ip_pim]/data_pim[ith_pim][ip_pim]);
                                                printf("weight_pim_FD_p%03d_ith%03d = %f \n",weight_pim,ip_pim,ith_pim);

still printing nan


  Double_t x[] = {1., TMath::QuietNaN(), 3., TMath::SignalingNaN(), 5.};
  for (unsigned i = 0; i < sizeof(x) / sizeof(Double_t); i++) {
    if (TMath::Finite(x[i])) cout << x[i] << endl;
    else cout << "it's a lulu" << endl;

Thank you, Wile.