You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
65 lines
1.1 KiB
65 lines
1.1 KiB
#include <stdio.h>
|
|
#include <limits.h>
|
|
|
|
#include "logarithmus.h"
|
|
#include "exponent.h"
|
|
|
|
double logX(double base, double value){
|
|
if(base == 1.0 || base <= 0.0 || value <= 0.0){
|
|
return -1.0;
|
|
}
|
|
return(logN(value)/logN(base));
|
|
}
|
|
|
|
double log10(double value){
|
|
return logX(10.0, value);
|
|
}
|
|
|
|
double log2(double value){
|
|
return logX(2.0, value);
|
|
}
|
|
double lns(double x, double eps){
|
|
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;
|
|
}
|
|
|
|
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){
|
|
return lns(x, 0.00000001);
|
|
}
|
|
else{
|
|
return lnb(x);
|
|
}
|
|
}
|
|
|