jdk/test/java/math/BigInteger/ExtremeShiftingTests.java
changeset 21420 a56f40ab71ce
parent 5506 202f599c92aa
child 21607 c91d2094ba1d
equal deleted inserted replaced
21419:a842a3bbee57 21420:a56f40ab71ce
    25  * @test
    25  * @test
    26  * @bug 6371401
    26  * @bug 6371401
    27  * @summary Tests of shiftLeft and shiftRight on Integer.MIN_VALUE
    27  * @summary Tests of shiftLeft and shiftRight on Integer.MIN_VALUE
    28  * @author Joseph D. Darcy
    28  * @author Joseph D. Darcy
    29  */
    29  */
       
    30 import java.math.BigInteger;
    30 import static java.math.BigInteger.*;
    31 import static java.math.BigInteger.*;
    31 
    32 
    32 public class ExtremeShiftingTests {
    33 public class ExtremeShiftingTests {
    33     public static void main(String... args) {
    34     public static void main(String... args) {
       
    35         BigInteger bi = ONE.shiftLeft(Integer.MIN_VALUE);
       
    36         if (!bi.equals(ZERO))
       
    37             throw new RuntimeException("1 << " + Integer.MIN_VALUE);
       
    38 
       
    39         bi = ZERO.shiftLeft(Integer.MIN_VALUE);
       
    40         if (!bi.equals(ZERO))
       
    41             throw new RuntimeException("0 << " + Integer.MIN_VALUE);
       
    42 
       
    43         bi = BigInteger.valueOf(-1);
       
    44         bi = bi.shiftLeft(Integer.MIN_VALUE);
       
    45         if (!bi.equals(BigInteger.valueOf(-1)))
       
    46             throw new RuntimeException("-1 << " + Integer.MIN_VALUE);
       
    47 
    34         try {
    48         try {
    35             ONE.shiftLeft(Integer.MIN_VALUE);
    49             ONE.shiftRight(Integer.MIN_VALUE);
    36             throw new RuntimeException("Should not reach here.");
    50             throw new RuntimeException("1 >> " + Integer.MIN_VALUE);
    37         } catch (ArithmeticException ae) {
    51         } catch (ArithmeticException ae) {
    38             ; // Expected
    52             ; // Expected
    39         }
    53         }
    40 
    54 
       
    55         bi = ZERO.shiftRight(Integer.MIN_VALUE);
       
    56         if (!bi.equals(ZERO))
       
    57             throw new RuntimeException("0 >> " + Integer.MIN_VALUE);
       
    58 
    41         try {
    59         try {
    42             ONE.shiftRight(Integer.MIN_VALUE);
    60             BigInteger.valueOf(-1).shiftRight(Integer.MIN_VALUE);
    43             throw new RuntimeException("Should not reach here.");
    61             throw new RuntimeException("-1 >> " + Integer.MIN_VALUE);
    44         } catch (ArithmeticException ae) {
    62         } catch (ArithmeticException ae) {
    45             ; // Expected
    63             ; // Expected
    46         }
    64         }
       
    65 
    47     }
    66     }
    48 }
    67 }