What’s wrong with using == to compare floats in Java?

According to this java.sun page == is the equality comparison operator for floating point numbers in Java. However, when I type this code: if(sectionID == currentSectionID) into my editor and run static analysis, I get: “JAVA0078 Floating point values compared with ==” What is wrong with using == to compare floating point values? What is … Read more

In Objective-C, what is the equivalent of Java’s “instanceof” keyword?

I would like to check whether an object (e.g. someObject) is assignable (cast-able) to a variable of another type (e.g. SpecifiedType). In Java, I can write: someObject instanceof SpecifiedType A related question is finding whether the runtime type of an object is equal to a another type. In Java, I can write: someObject.getClass().equals(SpecifiedType.class) How can … Read more

What’s the difference between IEquatable and just overriding Object.Equals()?

I want my Food class to be able to test whenever it is equal to another instance of Food. I will later use it against a List, and I want to use its List.Contains() method. Should I implement IEquatable<Food> or just override Object.Equals()? From MSDN: This method determines equality by using the default equality comparer, … Read more

Is False == 0 and True == 1 an implementation detail or is it guaranteed by the language?

Is it guaranteed that False == 0 and True == 1, in Python (assuming that they are not reassigned by the user)? For instance, is it in any way guaranteed that the following code will always produce the same results, whatever the version of Python (both existing and, likely, future ones)? 0 == False # … Read more