|
|
@ -8,7 +8,7 @@ double logX(double base, double value){ |
|
|
|
if(base == 1.0 || base <= 0.0 || value <= 0.0){ |
|
|
|
return -1.0; |
|
|
|
} |
|
|
|
return(logN(value, 0.00000001)/logN(base, 0.00000001)); |
|
|
|
return(logN(value)/logN(base)); |
|
|
|
} |
|
|
|
|
|
|
|
double log10(double value){ |
|
|
@ -18,41 +18,48 @@ double log10(double value){ |
|
|
|
double log2(double value){ |
|
|
|
return logX(2.0, value); |
|
|
|
} |
|
|
|
double lns(double x, double eps){ |
|
|
|
double yn = x - 1.0; |
|
|
|
double yn1 = yn; |
|
|
|
|
|
|
|
double logN(double x, double eps){ |
|
|
|
do{ |
|
|
|
yn = yn1; |
|
|
|
yn1 = yn + 2 * (x - exponential(yn)) / (x + exponential(yn)); |
|
|
|
} while (absD(yn - yn1) > eps); |
|
|
|
|
|
|
|
return yn1; |
|
|
|
} |
|
|
|
|
|
|
|
double lnb(double x){ |
|
|
|
int power_adjust = 0; |
|
|
|
while (x > 1.0) { |
|
|
|
x /= exponential(1); |
|
|
|
power_adjust++; |
|
|
|
} |
|
|
|
while (x < .25) { |
|
|
|
x *= exponential(1); |
|
|
|
power_adjust--; |
|
|
|
} |
|
|
|
|
|
|
|
x -= 1.0; |
|
|
|
double t = 0.0, s = 1.0, z = x; |
|
|
|
for (int k=1; k<=100; k++) { |
|
|
|
t += z * s / k; |
|
|
|
z *= x; |
|
|
|
s = -s; |
|
|
|
} |
|
|
|
return t + power_adjust; |
|
|
|
} |
|
|
|
|
|
|
|
double logN(double x){ |
|
|
|
if(x <= 0){ |
|
|
|
return -1.0; |
|
|
|
} |
|
|
|
if(x<200){ |
|
|
|
double yn = x - 1.0; |
|
|
|
double yn1 = yn; |
|
|
|
|
|
|
|
do{ |
|
|
|
yn = yn1; |
|
|
|
yn1 = yn + 2 * (x - exponential(yn)) / (x + exponential(yn)); |
|
|
|
} while (absD(yn - yn1) > eps); |
|
|
|
|
|
|
|
return yn1; |
|
|
|
return lns(x, 0.00000001); |
|
|
|
} |
|
|
|
else{ |
|
|
|
int power_adjust = 0; |
|
|
|
while (x > 1.0) { |
|
|
|
x /= exponential(1); |
|
|
|
power_adjust++; |
|
|
|
} |
|
|
|
while (x < .25) { |
|
|
|
x *= exponential(1); |
|
|
|
power_adjust--; |
|
|
|
} |
|
|
|
|
|
|
|
x -= 1.0; |
|
|
|
double t = 0.0, s = 1.0, z = x; |
|
|
|
for (int k=1; k<=100; k++) { |
|
|
|
t += z * s / k; |
|
|
|
z *= x; |
|
|
|
s = -s; |
|
|
|
} |
|
|
|
return t + power_adjust; |
|
|
|
return lnb(x); |
|
|
|
} |
|
|
|
} |
|
|
|
|