Return-Path: Delivered-To: apmail-harmony-commits-archive@www.apache.org Received: (qmail 66199 invoked from network); 13 Sep 2007 13:12:11 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 13 Sep 2007 13:12:11 -0000 Received: (qmail 21211 invoked by uid 500); 13 Sep 2007 13:12:04 -0000 Delivered-To: apmail-harmony-commits-archive@harmony.apache.org Received: (qmail 21188 invoked by uid 500); 13 Sep 2007 13:12:04 -0000 Mailing-List: contact commits-help@harmony.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@harmony.apache.org Delivered-To: mailing list commits@harmony.apache.org Received: (qmail 21179 invoked by uid 99); 13 Sep 2007 13:12:04 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 13 Sep 2007 06:12:04 -0700 X-ASF-Spam-Status: No, hits=-100.0 required=10.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.3] (HELO eris.apache.org) (140.211.11.3) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 13 Sep 2007 13:13:49 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id 57BCC1A9832; Thu, 13 Sep 2007 06:11:48 -0700 (PDT) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r575302 - /harmony/enhanced/classlib/trunk/modules/math/src/main/java/java/math/BigInteger.java Date: Thu, 13 Sep 2007 13:11:48 -0000 To: commits@harmony.apache.org From: tellison@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20070913131148.57BCC1A9832@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: tellison Date: Thu Sep 13 06:11:47 2007 New Revision: 575302 URL: http://svn.apache.org/viewvc?rev=575302&view=rev Log: Apply patch HARMONY-4780 ([classlib][math] BigInteger pow speed-up) Modified: harmony/enhanced/classlib/trunk/modules/math/src/main/java/java/math/BigInteger.java Modified: harmony/enhanced/classlib/trunk/modules/math/src/main/java/java/math/BigInteger.java URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/math/src/main/java/java/math/BigInteger.java?rev=575302&r1=575301&r2=575302&view=diff ============================================================================== --- harmony/enhanced/classlib/trunk/modules/math/src/main/java/java/math/BigInteger.java (original) +++ harmony/enhanced/classlib/trunk/modules/math/src/main/java/java/math/BigInteger.java Thu Sep 13 06:11:47 2007 @@ -25,10 +25,6 @@ import org.apache.harmony.math.internal.nls.Messages; -/** - * @author Intel Middleware Product Division - * @author Instituto Tecnologico de Cordoba - */ public class BigInteger extends Number implements Comparable, Serializable { @@ -679,19 +675,29 @@ return Multiplication.multiply(this, val); } - /** @ar.org.fitc.spec_ref */ public BigInteger pow(int exp) { - if (exp < 0){ + if (exp < 0) { // math.16=Negative exponent throw new ArithmeticException(Messages.getString("math.16")); //$NON-NLS-1$ } if (exp == 0) { return ONE; - } else if(exp == 1 || equals(ONE) || equals(ZERO)) { + } else if (exp == 1 || equals(ONE) || equals(ZERO)) { return this; } + + // if even take out 2^x factor which we can + // calculate by shifting. + if (!testBit(0)) { + int x = 1; + BigInteger factor = BigInteger.ONE.shiftLeft(exp); + while (!testBit(x)) { + factor = factor.shiftLeft(exp); + x++; + } + return factor.multiply(this.shiftRight(x).pow(exp)); + } return Multiplication.pow(this, exp); - } /** @ar.org.fitc.spec_ref */