Browse Source

add support to ln function for larger numbers

master
fdai7848 11 months ago
parent
commit
f05d7b4d4f
  1. 4
      src/exponent.c
  2. 43
      src/logarithmus.c

4
src/exponent.c

@ -1,5 +1,6 @@
#include <stdio.h> #include <stdio.h>
#include <limits.h> #include <limits.h>
#include <stdbool.h>
#include "exponent.h" #include "exponent.h"
#include "logarithmus.h" #include "logarithmus.h"
@ -63,9 +64,10 @@ unsigned long long fac(int x){
double exponential(double x){ double exponential(double x){
double sum = 0.0; double sum = 0.0;
for(int i = 0; i<=21; i++){
for(int i = 0; i<=20; i++){
sum += (1.0/fac(i)*(powerD(i,x))); sum += (1.0/fac(i)*(powerD(i,x)));
} }
return sum; return sum;
} }

43
src/logarithmus.c

@ -8,7 +8,7 @@ double logX(double b, double a){
if(b == 1.0 || b <= 0.0 || a <= 0.0){ if(b == 1.0 || b <= 0.0 || a <= 0.0){
return -1.0; return -1.0;
} }
return(logN(a, 0.000001)/logN(b, 0.000001));
return(logN(a, 0.00000001)/logN(b, 0.00000001));
} }
double logDec(double a){ double logDec(double a){
@ -22,14 +22,37 @@ double logBin(double a){
double logN(double x, double eps){ double logN(double x, double eps){
if(x <= 0){ if(x <= 0){
return -1.0; return -1.0;
}
double yn = x - 1.0;
double yn1 = yn;
}
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);
do{
yn = yn1;
yn1 = yn + 2 * (x - exponential(yn)) / (x + exponential(yn));
} while (absD(yn - yn1) > eps);
return yn1;
}
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 yn1;
}
Loading…
Cancel
Save