|
-
Feb 14th, 2004, 02:25 AM
#1
Thread Starter
Fanatic Member
Any root solver
Code:
static double PowerDec(double x, double a){
//Evaluates decimal powers from i+0.01 -> i+0.99
double b = 0;//value of the root.
int i = 0;
//Check special cases
if (a == 1)
return x;
//Check power if > 1.
while (a > 1) {
a -= 1;
i += 1;
}
//MAIN
if( (a>=0.01) && (a<0.125) ){ //0.11 1/9
while ((b*b*b*b*b*b*b*b*b) <= x) {
b += 0.0001;
}
}
if( (a>=0.125) && (a<0.14) ){ //0.125 1/8
while ((b*b*b*b*b*b*b*b) <= x) {
b += 0.0001;
}
}
if( (a>=0.16) && (a<=0.17) ){ //0.16 1/6
while ((b*b*b*b*b*b) <= x) {
b += 0.0001;
}
}
if( (a>=0.14) && (a<0.17) ){ //0.14 1/7
while ((b*b*b*b*b*b*b) <= x) {
b += 0.0001;
}
}
if( (a>0.17) && (a<0.25) ){ //0.2
while ((b*b*b*b*b) <= x) {
b += 0.0001;
}
}
if( (a>=0.25) && (a<0.3) ) {//0.25
while ((b*b*b*b) <= x) {
b += 0.0001;
}
}
if( (a>=0.3) && (a<0.45) ) {//0.3
while ((b*b*b) <= x) {
b += 0.0001;
}
}
if( (a>=0.45) && (a<0.55) ) {//0.5, just call sqrt
b=Sqrt(x);
}
if( (a>=0.55) && (a<0.65) ) {//0.6, 3/5
while ((b*b*b*b*b) <= (x*x*x)) {
b += 0.0001;
}
}
if( (a>=0.65) && (a<0.75) ) {//0.7, 7/10
while ((b*b*b*b*b*b*b*b*b*b) <= (x*x*x*x*x*x*x)) {
b += 0.0001;
}
}
if( (a>=0.75) && (a<0.85) ) {//0.8, 4/5
while ((b*b*b*b*b) <= (x*x*x*x)) {
b += 0.0001;
}
}
if( (a>=0.85) && (a<=0.99) ) {//0.9, 9/10
while ((b*b*b*b*b*b*b*b*b*b) <= (x*x*x*x*x*x*x*x*x)) {
b += 0.0001;
}
}
//Check if i>=1, multiply b by x i times until i becomes less than 1.
//IE x^(1.2) = x^1 * x^0.2
while (i>=1) {
b *= x;
i -= 1;
}
return b;
}
Please leave your comments thanks.

prog_tom
JOIN THE REVOLUTION!!!! Dual T3 backedup science community.
http://physics.sviesoft.com/forum
-
Feb 14th, 2004, 12:28 PM
#2
See the C++ version.
Why are you trying to recreate all the stuff from java.lang.Math? You really only learn about maths this way, and not so much about the language.
All the buzzt
 CornedBee
"Writing specifications is like writing a novel. Writing code is like writing poetry."
- Anonymous, published by Raymond Chen
Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|