Skip to content

Instantly share code, notes, and snippets.

@chrisvest
Created May 15, 2014 07:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chrisvest/962a788c36344223101f to your computer and use it in GitHub Desktop.
Save chrisvest/962a788c36344223101f to your computer and use it in GitHub Desktop.
public static void main(String[] args) {
outer:for (int i = Integer.MIN_VALUE; i < Integer.MAX_VALUE; i++) {
// Optimise the program by checking most likely candidates for
// coercion conflicts first.
boolean foundConflict = false;
for (int x = 1; x < 100; x++) {
// scala> for (x <- 1 until 15)
// yield ((x / 2) ^ (-1 * (x % 2)));
// res21: Seq[Int] =
// Vector(-1, 1, -2, 2, -3, 3, -4, 4, -5, 5, -6, 6, -7, 7)
int j = i + ((x / 2) ^ (-1 * (x % 2)));
if (((double) i) == ((double) j)) {
foundConflict = true;
System.out.printf(
"Coercion conflict: i = %s, j = %s, " +
"double i = %f, double j = %f%n",
i, j, (double) i, (double) j);
}
if (x >= 2 && !foundConflict) {
// The two most likely conflicting candidates have been
// checked, and found nothing. Let's move on to the next i.
continue outer;
}
}
}
System.out.println("Done");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment