...
Code Block | ||
---|---|---|
| ||
class WideSample { public static void main(String[] args) { int big = 1234567890; // The significand can store at most 23 bits if(Integer.highestOneBit(big) >> Math.pow(2, 23)) { throw new ArithmeticException(""Insufficient precision""); } float approx = big; System.out.println(big - (int)approx); // Prints zero when no precision is lost } } |
...
Wiki Markup |
---|
\[[JLS 05|AA. Java References#JLS 05]\] Section [5.1.2, Widening Primitive Conversion|http://java.sun.com/docs/books/jls/third_edition/html/conversions.html#5.1.2] |
...
INT31INT32-J. Do not rely on the write() method to output integers outside the range 0 to 255 use bitwise operators on integers incorrectly 06. Integers (INT) INT34-J. Perform explicit range checking to ensure integer operations do not overflow