|
|
|
![]() |
|
|||||||
|
||||||||
![]() |
| Thread Tools |
Rating:
|
Display Modes |
|
#1
|
|||
|
|||
|
Power Function
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.
|
|
#2
|
||||
|
||||
|
Re: Power Function
Isn't there already a power function in Java.lang.Math?
http://docs.oracle.com/javase/1.5.0/...e,%20double%29 |
|
#3
|
|||
|
|||
|
Re: Power Function
Yes in regular Java but not FRC version. Also in regular java its function is native so the class has no copyable code.
|
|
#4
|
||||
|
||||
|
Re: Power Function
Quote:
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)) |
|
#5
|
|||
|
|||
|
Re: Power Function
No it doesn't have log or exponent functions. And no the number of precision has to be more than the max value of double (1.7976931348623157 *10^308). If it's not then the program keeps running down to the base value, then get a runtime error.
|
|
#6
|
||||
|
||||
|
Re: Power Function
http://www.chiefdelphi.com/forums/sh...63&postcount=4
Quote:
|
|
#7
|
|||
|
|||
|
Re: Power Function
Ok thanks. I found it under squawk. Do you know if there are arrayLists, decimalFormat or java.net classes? Thanks again for your help.
Last edited by tyandjel94 : 10-02-2012 at 08:05 PM. |
![]() |
| Thread Tools | |
| Display Modes | Rate This Thread |
|
|