In ocaml, the expression 0.0 == 0.0 +. 0.0 is false. Gah! That is so stupid. I miss haskell.
Posted on September 17, 2006 07:29 PM
More programming articles
I'm still trying to wrap my brain around Lisp and the fact that (eq 2 2) may be false.
And this is by design, not a bug?
Posted by: Sjoerd Visscher at September 18, 2006 05:45 AMApparently yes, it is by design. == is used for pointer equality while = is used for structural equality. I'm guessing that since floats are 8 bytes, they can't be stored as a primitive value. Therefore == compares pointers instead of values. But I'm probably wrong about that.
Posted by: Kim at September 18, 2006 09:59 AMThis actually makes a lot of sense. If you're comparing values, 0.0 = 0.0 +. 0.0 is true, whereas == simply checks to see if each value references the same object.
Posted by: Eric Radman at October 3, 2006 07:12 PMEric, I disagree. If you're adding ints, then == works fine. It's only if you're adding doubles that it breaks. In my world, any language that treats ints as non-reference-types also treats doubles as non-reference types. Therefore this is confusing and unexpected.
Posted by: Kim at October 3, 2006 07:21 PMYou should be using = instead of ==. Only use == when you know exactly what it does, e.g. when you're writing code to traverse cyclic data structures.