Return-Path: Delivered-To: apmail-commons-dev-archive@www.apache.org Received: (qmail 54251 invoked from network); 8 Jun 2010 15:29:29 -0000 Received: from unknown (HELO mail.apache.org) (140.211.11.3) by 140.211.11.9 with SMTP; 8 Jun 2010 15:29:29 -0000 Received: (qmail 93818 invoked by uid 500); 8 Jun 2010 15:29:28 -0000 Delivered-To: apmail-commons-dev-archive@commons.apache.org Received: (qmail 93700 invoked by uid 500); 8 Jun 2010 15:29:28 -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 93692 invoked by uid 99); 8 Jun 2010 15:29:28 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 08 Jun 2010 15:29:28 +0000 X-ASF-Spam-Status: No, hits=-0.0 required=10.0 tests=SPF_PASS X-Spam-Check-By: apache.org Received-SPF: pass (nike.apache.org: local policy) Received: from [68.15.63.109] (HELO mantissa.rossi.com) (68.15.63.109) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 08 Jun 2010 15:29:22 +0000 Received: from mantissa.rossi.com (localhost [127.0.0.1]) by mantissa.rossi.com (8.14.3/8.8.4) with ESMTP id o58FT1am023218 for ; Tue, 8 Jun 2010 11:29:01 -0400 Received: from localhost (wrossi@localhost) by mantissa.rossi.com (8.14.3/8.14.3/Submit) with ESMTP id o58FT1AR023215 for ; Tue, 8 Jun 2010 11:29:01 -0400 X-Authentication-Warning: mantissa.rossi.com: wrossi owned process doing -bs Date: Tue, 8 Jun 2010 11:29:01 -0400 (EDT) From: Bill Rossi X-X-Sender: wrossi@mantissa.rossi.com To: dev@commons.apache.org Subject: Re: [math] elementary functions. In-Reply-To: Message-ID: References: User-Agent: Alpine 1.10 (DEB 962 2008-03-14) MIME-Version: 1.0 Content-Type: MULTIPART/MIXED; BOUNDARY="256142655-1305864294-1276010941=:21986" X-Virus-Checked: Checked by ClamAV on apache.org --256142655-1305864294-1276010941=:21986 Content-Type: TEXT/PLAIN; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 8BIT I've looked at StrictMath, generally Math appears to delegates to StrictMath. StrictMath is implemented by the C fdlibm library. This is what I've implemented to date, the code will compile and run on JDK 1.4 and later. It may work on older JDKs, but I don't have them available for testing. Note that functions like expm1 are not available in earlier JDKs. public class FastMath extends java.lang.Object{ public FastMath(); public static double exp(double); public static double expm1(double); public static double log(double); public static double log1p(double); public static double log10(double); public static double pow(double, double); public static double sin(double); public static double cos(double); public static double tan(double); public static double atan(double); public static double atan2(double, double); public static double toRadians(double); public static double toDegrees(double); public static double abs(double); public static double ulp(double); public static double floor(double); public static double ceil(double); public static double rint(double); public static long round(double); static {}; } Performance test gives these results: Function Time Result Function Time Result ---------------------------------------------------------------------------------------------- StrictMath.log 967 1.5118099917827207E8 FastMath.log 553 1.5118099917827207E8 StrictMath.pow 3199 4.6455095486440872E16 FastMath.pow 1967 4.645509548644088E16 StrictMath.exp 1079 2.2025454782076317E10 FastMath.exp 562 2.2025454782076317E10 StrictMath.sin 1151 1839071.8010869955 FastMath.sin 766 1839071.8010869955 StrictMath.cos 1173 -544020.191353572 FastMath.cos 665 -544020.191353572 StrictMath.tan 1568 -5.024600819552688E7 FastMath.tan 1081 -5.024600819552688E7 StrictMath.atan 1079 1.2403715749052648E7 FastMath.atan 902 1.2403715749052648E7 StrictMath.expm1 727 -9899999.500018543 FastMath.expm1 773 -9899999.500018543 This table shows execution time for 10,000,000 calls in milliseconds. The result printed is there to prevent the JIT from optimizing away the calculation entirely. Note that some functions such as exp are nearly twice as fast. I've seen it 3 times faster on different processors. The preformance varies by the relative speed of calculation vs memory lookups. The functions are implemented as tables of values in extra precision (approx 70 bits), and then interpolated with a minimax polynomial. Typical test code: x = 0; time = System.currentTimeMillis(); for (int i=0; i<10000000; i++) x+=StrictMath.exp(i/1000000.0); time = System.currentTimeMillis() - time; System.out.print("StrictMath.exp "+time+"\t"+x+"\t"); x = 0; time = System.currentTimeMillis(); for (int i=0; i<10000000; i++) x+=FastMath.exp(i/1000000.0); time = System.currentTimeMillis() - time; System.out.println("FastMath.exp "+time+"\t"+x); To test accuracy, I'd compute results and compare them to an aribitrary precision math library. On Tue, 8 Jun 2010, James Carman wrote: > Have you tried looking at StrictMath? > > On Tue, Jun 8, 2010 at 10:44 AM, Ted Dunning wrote: >> Bill, >> >> Which functions do you have? >> >> Anything more than the standard sin, cos, exp and log? >> >> >> On Tue, Jun 8, 2010 at 6:52 AM, Bill Rossi wrote: >> >>> I have developed over the past year a set of elementary functions similar >>> to those in java.lang.Math, but with the following characteristics: >>> >>> * Higher performance. >>> * Better accuracy. �Results are accurate to slightly more that +/- 0.5 ULP. >>> * Pure Java. �The standard Math class is impleneted via JNI, and thus takes >>> a performance hit. >>> >> > > --------------------------------------------------------------------- > To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org > For additional commands, e-mail: dev-help@commons.apache.org > --256142655-1305864294-1276010941=:21986 Content-Type: text/plain; charset=us-ascii --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org For additional commands, e-mail: dev-help@commons.apache.org --256142655-1305864294-1276010941=:21986--