Thread: Power Function
View Single Post
  #4   Spotlight this post!  
Unread 02-10-2012, 17:52
Ether's Avatar
Ether Ether is offline
systems engineer (retired)
no team
 
Join Date: Nov 2009
Rookie Year: 1969
Location: US
Posts: 8,042
Ether has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond repute
Re: Power Function

Quote:
Originally Posted by tyandjel94 View Post
I was wondering the best way to make a power function for any number. I came up with the conclusion of using Newton's root finding Method which computes is a method for finding successively better approximations to the roots (or zeroes) of a real-valued function. I was able to find that this worked perfectly on a calculator, but it didn't work when you program it. This is because the long, double, and float data types are not long enough. A bigDecimal is needed, but the FRC Java which is Java ME doesn't not have that class. Is there a way to work around this? Thanks a lot.
I suspect you did not program it correctly. Double precision floats should have adequate resolution for this.

But there may be a better way. Does the Java FRC runtime math library support logarithms and exponentiation?

If so, there's a simple solution:

You want to compute:

power = base^x

... for any positive real base and x, correct?

To do so, substitute e^ln(base) for base to get:

power = e^(x*ln(base))


Reply With Quote