Return-Path: X-Original-To: apmail-commons-dev-archive@www.apache.org Delivered-To: apmail-commons-dev-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id EEAB68FE6 for ; Wed, 7 Sep 2011 10:23:15 +0000 (UTC) Received: (qmail 92136 invoked by uid 500); 7 Sep 2011 10:23:12 -0000 Delivered-To: apmail-commons-dev-archive@commons.apache.org Received: (qmail 91898 invoked by uid 500); 7 Sep 2011 10:22:57 -0000 Mailing-List: contact dev-help@commons.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: "Commons Developers List" Delivered-To: mailing list dev@commons.apache.org Received: (qmail 91889 invoked by uid 99); 7 Sep 2011 10:22:52 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 07 Sep 2011 10:22:52 +0000 X-ASF-Spam-Status: No, hits=-0.7 required=5.0 tests=FREEMAIL_FROM,RCVD_IN_DNSWL_LOW,SPF_PASS X-Spam-Check-By: apache.org Received-SPF: pass (nike.apache.org: domain of sebbaz@gmail.com designates 209.85.220.171 as permitted sender) Received: from [209.85.220.171] (HELO mail-vx0-f171.google.com) (209.85.220.171) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 07 Sep 2011 10:22:45 +0000 Received: by vxh2 with SMTP id 2so684954vxh.30 for ; Wed, 07 Sep 2011 03:22:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type:content-transfer-encoding; bh=Au+Fu3cZcHw9Z/e1cho6fNniBB7mdR73aol7jhf+Zgs=; b=w1ZxLUmD2xCyd+HRZMOwWV/II0IYPx+J3eyOAH5WtbGvC5mCG0ViWhYk1KaZ9iqJjn XF7Kk3QELND+E7wDYQk/fAguYc7vAxfd/CwCzdujV3DomksWX1Muzk1exoP9cXlWLyYT siY2DiYbCCj6qCSwRZt99yJfQrGX6keSWginI= MIME-Version: 1.0 Received: by 10.220.5.210 with SMTP id 18mr1831909vcw.83.1315390944592; Wed, 07 Sep 2011 03:22:24 -0700 (PDT) Received: by 10.220.171.145 with HTTP; Wed, 7 Sep 2011 03:22:24 -0700 (PDT) In-Reply-To: <20110907094657.GQ2590@dusk.harfang.homelinux.org> References: <20110906210659.51A182388A67@eris.apache.org> <20110906230459.GZ19625@dusk.harfang.homelinux.org> <20110907094657.GQ2590@dusk.harfang.homelinux.org> Date: Wed, 7 Sep 2011 11:22:24 +0100 Message-ID: Subject: Re: svn commit: r1165846 [2/2] - /commons/proper/math/trunk/src/main/java/org/apache/commons/math/util/FastMath.java From: sebb To: Commons Developers List Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable X-Virus-Checked: Checked by ClamAV on apache.org On 7 September 2011 10:46, Gilles Sadowski w= rote: > On Wed, Sep 07, 2011 at 12:42:06AM +0100, sebb wrote: >> On 7 September 2011 00:04, Gilles Sadowski wrote: >> > Hello. >> > >> >> Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/= math/util/FastMath.java >> >> URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/= java/org/apache/commons/math/util/FastMath.java?rev=3D1165846&r1=3D1165845&= r2=3D1165846&view=3Ddiff >> >> =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D >> >> --- commons/proper/math/trunk/src/main/java/org/apache/commons/math/u= til/FastMath.java (original) >> >> +++ commons/proper/math/trunk/src/main/java/org/apache/commons/math/u= til/FastMath.java Tue Sep =A06 21:06:58 2011 >> >> @@ -74,31 +74,6147 @@ public class FastMath { >> >> =A0 =A0 =A0/** Napier's constant e, base of the natural logarithm. */ >> >> =A0 =A0 =A0public static final double E =3D 2850325.0 / 1048576.0 + 8= .254840070411028747e-8; >> >> >> >> + =A0 =A0private static final int EXP_INT_TABLE_MAX_INDEX =3D 750; >> >> + =A0 =A0private static final int EXP_INT_TABLE_LEN =3D EXP_INT_TABLE= _MAX_INDEX * 2; >> >> + >> >> =A0 =A0 =A0/** Exponential evaluated at integer values, >> >> - =A0 =A0 * exp(x) =3D =A0expIntTableA[x + 750] + expIntTableB[x+750]= . >> >> + =A0 =A0 * exp(x) =3D =A0expIntTableA[x + EXP_INT_TABLE_MAX_INDEX] += expIntTableB[x+EXP_INT_TABLE_MAX_INDEX]. >> >> =A0 =A0 =A0 */ >> >> - =A0 =A0private static final double EXP_INT_TABLE_A[] =3D new double= [1500]; >> >> + =A0 =A0private static final double EXP_INT_TABLE_A[] =3D >> >> + =A0 =A0{ >> >> + =A0 =A0 =A0 =A0+0.0d, >> >> + =A0 =A0 =A0 =A0Double.NaN, >> > >> > [More than 6000 lines stripped.] >> > >> > Wouldn't it be advantageous to store those tabulated data in separate >> > Java files? E.g. >> > --- >> > class ExpIntTables { >> > =A0 =A0static final double[] A =3D { >> > =A0 =A0 =A0// Very long table. >> > =A0 =A0}; >> > =A0 =A0static final double[] B =3D { >> > =A0 =A0 =A0// ... >> > =A0 =A0}; >> > --- >> > >> > And in "FastMath.java": >> > --- >> > public class FastMath { >> > =A0 =A0private static final double[] EXP_INT_TABLE_A =3D ExpIntTables.= A; >> > =A0 =A0private static final double[] EXP_INT_TABLE_B =3D ExpIntTables.= B; >> > } >> > --- >> >> That would be possible, but would require the tables to be >> non-private, increasing the theoretical risk of accidental changes. > > I know, but having "package" access level reduces the risk to our own > mistakes, similar to any bug we can introduce when writing code. Except that there are now many more files that may need to be debugged. > One can also assumes that the tables =A0will need much less changes (if > at all) than actual code in "FastMath.java"; so having them in separate > files could reduce the risk of messing with them... And of course, there = is > the practical advantage of not having to load/scroll 6000+ lines in orde = to > have a look at the code. We could move the tables and disabled setup code to the end of the source f= ile. Some of the setup code could be moved into a separate class - e.g. the slowExp, slowSin and SlowCos methods use the FACT table, which is not needed elsewhere. > By the way, how much faster is now the first use of a method from > "FastMath"? Not checked. Perhaps the OP of the JIRA will be able to help there. That probably needs to be the next step. > > Regards, > Gilles > > --------------------------------------------------------------------- > To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org > For additional commands, e-mail: dev-help@commons.apache.org > > --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org For additional commands, e-mail: dev-help@commons.apache.org