⭐ in reply to My floating point comparison does not work. Why ?
This might become important in such situations as passing a sorting or searching function. I am more familiar with this situation in C++ and Java. In Java, there is such a thing as the "equals contract", which states that the equals function must be reflexive (a==a), symmetric (a==b, b==a) and transitive (a==b, b==c, a==c). This is important for building HashSet and HashMap objects, and there are similar rules in C++ for the STL containers and algorithms.
Being something of a perl noob, I don't know if there are similar constraints in Perl libraries, but it's a good rule to bear in mind anyway.
If a comparison function is not transitive, you are just pushing the surprising behaviour into a darker corner.
|
---|