Double.NaN Is Evil
I
don't know what Sun
had in
mind when creating Double.NaN number.
It is very inintuitive to use. I
am sure
every single
developer out
there fell in
the trap of trying to find out if a double
was NaN or
not using:
Double.NaN == myDouble
This does not work (I
don't know the real reason why),
one has to use:
Double.isNaN(myDouble)
Not intuitive!
This happens because Java's implementation of NaN follows IEEE 754 which I understand specifies this behaviour.
ReplyDeleteI also had many headaches with NaN values. Many algorithms do not cope well with it, or the handling was added as an afterthought. There are a few entries about NaN in my blog:
ReplyDeletehttp://www.jroller.com/ethdsy/entry/nan_of_them
http://www.jroller.com/ethdsy/entry/looking_for_max
http://www.jroller.com/ethdsy/entry/java_io_does_not_save
many thanks for the post
ReplyDeleteYou should use Double.compare or Double.compareTo for this, works like a charm!
ReplyDelete