Good day. The problem is what? - produces an error: "invalid operands of types 'double' and 'double (const char *) throw ()' to binary 'operator =='"
Here is a code snippet in which it gives an error:

double Opredel(){ int swapc= triangulat(); double opredel=mat[0][0]; for(int i=1;i<size;i++){ mat[i][i]= 0; opredel*=mat[i][i]; } if(swapc % 2 != 0 ){ opredel *=-1; } if(opredel == nan){ opredel = 0; } return opredel; } 

If it is not difficult, then explain why this error occurs, in order to avoid such mistakes in the future. Thank.

  • My crystal ball tells me that nan is a function and you forgot to add parentheses to call it. - VTT
  • The fact is that when calculating the determinant, the value nan sometimes appears in the matrix cells. And I want to check that if because of this the whole determinant turns into nan, then just convert it to 0. (the call as a function tried, another error crawled out). - Vlad Lesnoy
  • one
    So you decide what nan and what you are going to do with it. - VTT
  • So I decided. I need to check the value of the determinant on whether it is equal to nan. - Vlad Forest
  • @ Vladlesnoy: And? What opredel == nan you think that you can just take and write opredel == nan ? - AnT pm

1 answer 1

It is impossible to compare with NaN, it is always false - by definition :)

Look at the isnan function, or, alternatively, since the NaN comparison is always false, you can check it like this:

 bool is_nan(double x) { return x != x; } 

Just keep in mind that not all compilers support this (as far as I remember, Watcom did not think so ... but I don’t remember what) and the second is such a test - it speaks more about the incorrectness of the algorithm itself ...

  • one
    Thanks found in the calculations division by 0 now eliminated this check is not needed. - Vlad Lesnoy