Return-Path: Delivered-To: apmail-commons-dev-archive@www.apache.org Received: (qmail 55486 invoked from network); 8 Jun 2010 18:59:28 -0000 Received: from unknown (HELO mail.apache.org) (140.211.11.3) by 140.211.11.9 with SMTP; 8 Jun 2010 18:59:28 -0000 Received: (qmail 45342 invoked by uid 500); 8 Jun 2010 18:59:28 -0000 Delivered-To: apmail-commons-dev-archive@commons.apache.org Received: (qmail 45254 invoked by uid 500); 8 Jun 2010 18:59: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 45246 invoked by uid 99); 8 Jun 2010 18:59: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 18:59:28 +0000 X-ASF-Spam-Status: No, hits=0.7 required=10.0 tests=FREEMAIL_FROM,RCVD_IN_DNSWL_NONE,SPF_NEUTRAL X-Spam-Check-By: apache.org Received-SPF: neutral (nike.apache.org: local policy) Received: from [194.206.126.239] (HELO smtp.nordnet.fr) (194.206.126.239) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 08 Jun 2010 18:59:20 +0000 Received: from lehrin (84.216.20.81.dynamic.adsl.abo.nordnet.fr [81.20.216.84]) by smtp.nordnet.fr (Postfix) with ESMTP id 5BFD63400C for ; Tue, 8 Jun 2010 20:58:58 +0200 (CEST) Received: by lehrin (Postfix, from userid 5001) id 7C5A34166; Tue, 8 Jun 2010 20:58:59 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on lehrin.spaceroots.local X-Spam-Level: Received: from lehrin.spaceroots.local (lehrin.spaceroots.local [127.0.0.1]) by lehrin (Postfix) with ESMTP id 438224163 for ; Tue, 8 Jun 2010 20:58:54 +0200 (CEST) Message-ID: <4C0E92ED.9080004@free.fr> Date: Tue, 08 Jun 2010 20:58:53 +0200 From: Luc Maisonobe User-Agent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.1.9) Gecko/20100423 Thunderbird/3.0.4 MIME-Version: 1.0 To: Commons Developers List Subject: Re: [math] elementary functions. References: In-Reply-To: X-Enigmail-Version: 1.0.1 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 8bit X-Virus-Checked: Checked by ClamAV on apache.org X-Old-Spam-Status: No, score=-1.0 required=5.0 tests=ALL_TRUSTED,FREEMAIL_FROM autolearn=unavailable version=3.3.1 Le 08/06/2010 17:29, Bill Rossi a �crit : > > 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. This is really impressive and interesting. Do you intend to maintain it if is included in commons math ? The Apache Software Foundation is all about growing and maintaining a community around code, it is not only about code, so people are welcome to join. Also as you developed it outside of the project, if you want to contribute it you would have to provide a Software Grant for it (see from the IP owner, which may be you or your employer depending on how the code was developed in the first time. Thank you for this interesting proposal Luc > > 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 >> > > > > --------------------------------------------------------------------- > 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