Check two float/double values for exact equality

Piracy1996

New Member
Whats an elegant, readable and non-verbose way of comparing two floating point value for exact equality? As simple as it may sound, its a wicked problem. The == operator doesn't get the job done for NaN and also has special treatment for zero:\[code\](+0.0 == -0.0) -> trueDouble.NaN == Double.NaN -> false\[/code\]But I want to determine if two values are exactly the same (but I do not care for different NaN patterns, so any NaN == any other NaN -> true).I can do this with this ugly Monster piece of code:\[code\]Double.doubleToLongBits(a) == Double.doubleToLongBits(b)\[/code\]Is there a better way to write this (and make the intent obvious)?
 
Back
Top