The Source for Java Technology Collaboration
User: Password:



Start New Message Delete Post a Reply

Article: 
 Creating a Java ME Math.pow() Method
Subject:  Can do better
Date:  2007-11-07 13:15:02
From:  mthornton


First for the integer powers you can do much better than n multiplications to evaluate x**n.

For the fractional exponent I would reach for my copy of the "Handbook of Mathematical Functions" edited by Abramowitz and Stegun. This provides polynomial approximations for ln(1+x) where 0<=x<=1, accurate to 1e-5, 3e-8 or better than 1e-9. Another set of functions are provided for exp.
Pick a set of suitable polynomials for the required accuracy, add the code to reduce the values to the appropriate range(s) and you are done.

 Feed java.net RSS Feeds