This is the expression:
if( Math.abs(GH1[i]) < Double.valueOf("1E-100") ){
.
.
.
}
All variables are of double
type. It should be clear from the code about what I am trying to compare. I always assumed this would be correct in java , as the compiler never shows any errors either. But I recently read here that I should not use ==
for comparison of floating point numbers. Is it true of other relational operators? If I am not worried about NaN
, can I just use the built in relational operators in stead of the Double
or Float
functions?
Can I use the expression shown below?
if(GH1[i] < 0.0f) // if( Double.compare(GH1[i], 0.0f) < 0 )
tempSign = -1.0f;
else if(GH1[i] == 0.0f) // else if( Double.compare(GH1[i], 0.0f) == 0 )
tempSign = 0.0f;
else if(GH1[i] > 0.0f) // else if( Double.compare(GH1[i], 0.0f) > 0 )
tempSign = 1.0f;
Or does it have to use Double and Float's functions?