public void testPowNegativeNumToEvenExp(){
  byte aBytes[]={50,-26,90,69,120,32,63,-103,-14,35};
  int aSign=-1;
  int exp=4;
  byte rBytes[]={102,107,-122,-43,-52,-20,-27,25,-9,88,-13,75,78,81,-33,-77,39,27,-37,106,121,-73,108,-47,-101,80,-25,71,13,94,-7,-33,1,-17,-65,-70,-61,-3,-47};
  BigInteger aNumber=new BigInteger(aSign,aBytes);
  BigInteger result=aNumber.pow(exp);
  byte resBytes[]=new byte[rBytes.length];
  resBytes=result.toByteArray();
  for (int i=0; i < resBytes.length; i++) {
    assertTrue(resBytes[i] == rBytes[i]);
  }
  assertEquals("incorrect sign",1,result.signum());
}

public void testPowNegativeNumToEvenExp ( ) { byte aBytes [ ] = { 50 , - 26 , 90 , 69 , 120 , 32 , 63 , - 103 , - 14 , 35 } ; int aSign = - 1 ; int exp = 4 ; byte rBytes [ ] = { 102 , 107 , - 122 , - 43 , - 52 , - 20 , - 27 , 25 , - 9 , 88 , - 13 , 75 , 78 , 81 , - 33 , - 77 , 39 , 27 , - 37 , 106 , 121 , - 73 , 108 , - 47 , - 101 , 80 , - 25 , 71 , 13 , 94 , - 7 , - 33 , 1 , - 17 , - 65 , - 70 , - 61 , - 3 , - 47 } ; BigInteger aNumber = new BigInteger ( aSign , aBytes ) ; BigInteger result = aNumber . pow ( exp ) ; byte resBytes [ ] = new byte [ rBytes . length ] ; resBytes = result . toByteArray ( ) ; for ( int i = 0 ; i < resBytes . length ; i ++ ) { assertTrue ( resBytes [ i ] == rBytes [ i ] ) ; } assertEquals ( "incorrect sign" , 1 , result . signum ( ) ) ; }
exponentiation of a negative number to an even exponent .
