Posted Apr 26, 2012 0:10 UTC (Thu) by IkeTo (subscriber, #2122)
[Link]
It depends on what you call "screw it up intentionally". The following program output "true" for most numbers larger than 16777216 or smaller than -16777217. It is 127/128 of the range [-2^31, 2^31-1] of int:
public class T {
public static void main(String[] args) {
int a = Integer.parseInt(args[0]);
float b = a;
int c = a + 1;
System.out.println(a == b && b == c && a != c);
}
}
Similar behavior can be found if you replace int by long and float by double.
PHP: a fractal of bad design (fuzzy notepad)
Posted Apr 26, 2012 1:50 UTC (Thu) by Cyberax (✭ supporter ✭, #52523)
[Link]
That's completely expected and correct behavior of equality comparisons involving floating point numbers. It's also noted in every textbook under the DO NOT USE category.