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

  1. #include <stdio.h>
  2. #include <limits.h>
  3. #include "logarithmus.h"
  4. #include "exponent.h"
  5. double logX(double base, double value){
  6. if(base == 1.0 || base <= 0.0 || value <= 0.0){
  7. return -1.0;
  8. }
  9. return(logN(value)/logN(base));
  10. }
  11. double log10(double value){
  12. return logX(10.0, value);
  13. }
  14. double log2(double value){
  15. return logX(2.0, value);
  16. }
  17. double lns(double x, double eps){
  18. double yn = x - 1.0;
  19. double yn1 = yn;
  20. do{
  21. yn = yn1;
  22. yn1 = yn + 2 * (x - exponential(yn)) / (x + exponential(yn));
  23. } while (absD(yn - yn1) > eps);
  24. return yn1;
  25. }
  26. double lnb(double x){
  27. int power_adjust = 0;
  28. while (x > 1.0) {
  29. x /= exponential(1);
  30. power_adjust++;
  31. }
  32. while (x < .25) {
  33. x *= exponential(1);
  34. power_adjust--;
  35. }
  36. x -= 1.0;
  37. double t = 0.0, s = 1.0, z = x;
  38. for (int k=1; k<=100; k++) {
  39. t += z * s / k;
  40. z *= x;
  41. s = -s;
  42. }
  43. return t + power_adjust;
  44. }
  45. double logN(double x){
  46. if(x <= 0){
  47. return -1.0;
  48. }
  49. if(x<200){
  50. return lns(x, 0.00000001);
  51. }
  52. else{
  53. return lnb(x);
  54. }
  55. }