Math.pow

Hi all, I've got a simple question:4 to the power of 29 is 288230376151711744.The following results in 288230376151711740 though.double t=Math.pow(4,29);Why? (Writing your own pow-method naturally solves the problem, but what's happening here?)
[281 byte] By [cyberdaemon22222a] at [2007-11-27 8:43:23]
# 1
you're running up against the innate imprecision of double.
petes1234a at 2007-7-12 20:43:04 > top of Java-index,Java Essentials,Java Programming...
# 2
consider using BigInteger and its pow function rather than double. http://java.sun.com/j2se/1.5.0/docs/api/java/math/BigInteger.html#pow(int)Message was edited by: petes1234
petes1234a at 2007-7-12 20:43:04 > top of Java-index,Java Essentials,Java Programming...
# 3

For instance:

public static void main(String[] args)

{

BigInteger myBigInt = new BigInteger("4");

BigInteger resultBigInt = myBigInt.pow(29);

double resultDbl = resultBigInt.doubleValue();

System.out.println("BigInteger Result: " + resultBigInt.toString());

System.out.println("Double Result:" + String.valueOf(resultDbl));

}

petes1234a at 2007-7-12 20:43:04 > top of Java-index,Java Essentials,Java Programming...
# 4
petes1234, thanks a lot for your quick and clear reply.
cyberdaemon22222a at 2007-7-12 20:43:04 > top of Java-index,Java Essentials,Java Programming...