KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
What is 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: (+0.0 == -0.0) -> true Double.NaN == Double.NaN -> false 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: Double.doubleToLongBits(a) == Double.doubleToLongBits(b) Is there a better way to write this (and make the intent obvious)?
Tags (comma-separated)
Save Edits
Cancel