Strange output from Java typecast <p>I am playing around with simple encryption using RSA algorithms and found a strange bug.</p> <pre><code>private static Integer testEnc(Integer value){ Integer val = (int)Math.pow(value, 37); return val % 437; } private static Integer testDec(Integer value){ Integer val = new Integer((int)Math.pow(value, 289)); return val % 437; } public static void main(String[] args) { System.out.print("Encode 55 = "); Integer encoded = testEnc(2); System.out.println(encoded + "\n"); System.out.print(encoded + " decoded = "); Integer decoded = testDec(3977645); System.out.println(decoded + "n"); } </code></pre> <p>Both of the following functions return 97 regardless of input. If I comment out the modulus and just return val, the returned value is 2147483647.</p> <p>Type casting double to int seems to be the issue but I am not sure why this is. These methods are static only because I was calling them from a main method.</p>