// Note that $opt$ is a marker for the optimizing compiler to test // it does compile the method, and that $noinline$ is a marker to // test that it does not inline it. publicclass NegTest {
privatestaticvoid negInt() {
assertEquals(-1, $opt$noinline$NegInt(1));
assertEquals(1, $opt$noinline$NegInt(-1));
assertEquals(0, $opt$noinline$NegInt(0));
assertEquals(51, $opt$noinline$NegInt(-51));
assertEquals(-51, $opt$noinline$NegInt(51));
assertEquals(2147483647, $opt$noinline$NegInt(-2147483647)); // -(2^31 - 1)
assertEquals(-2147483647, $opt$noinline$NegInt(2147483647)); // 2^31 - 1 // From the Java 7 SE Edition specification: // http://docs.oracle.com/javase/specs/jls/se7/html/jls-15.html#jls-15.15.4 // // For integer values, negation is the same as subtraction from // zero. The Java programming language uses two's-complement // representation for integers, and the range of two's-complement // values is not symmetric, so negation of the maximum negative // int or long results in that same maximum negative number. // Overflow occurs in this case, but no exception is thrown. // For all integer values x, -x equals (~x)+1.''
assertEquals(-2147483648, $opt$noinline$NegInt(-2147483648)); // -(2^31)
}
assertEquals(9223372036854775807L, $opt$noinline$NegLong(-9223372036854775807L)); // -(2^63 - 1)
assertEquals(-9223372036854775807L, $opt$noinline$NegLong(9223372036854775807L)); // 2^63 - 1 // See remark regarding the negation of the maximum negative // (long) value in negInt().
assertEquals(-9223372036854775808L, $opt$noinline$NegLong(-9223372036854775808L)); // -(2^63)
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.