I know that isn’t save to directly compare two double values after some calculations are involved.
But can I compare safely for equality a value initialized from a literal with the same literal used for initialization?
For example:
Double[] dValues = [...];
double minValue = Double.MAX_VALUE;
for(Double d:dValues) {
if(d!=null)
minValue = Math.min(d,minValue)
}
//Is that safe?
boolean someValueFound = minValue!=Double.MAX_VALUE
Yes, in this case it will be safe.
It will be always safe as long as you will be not performing any computations/casting/etc. on the affected value – which would might cause some roundings.
This is also safe, because the comparison happens on native/simple types, the outcome would be different if you would use Double instead of double.