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.

72 lines
1.3 KiB

12 months ago
12 months ago
  1. #include <stdio.h>
  2. #include <limits.h>
  3. #include <stdbool.h>
  4. #include "exponent.h"
  5. #include "logarithmus.h"
  6. double absD(double x){
  7. if(x<0){
  8. return -1 * x;
  9. }
  10. return x;
  11. }
  12. double p(double exp, double base){
  13. double prod = 1.0;
  14. if(exp==0.0){
  15. return 1;
  16. }else{
  17. for(int i = 1; i <= (int) exp; i++){
  18. prod *= base;
  19. }
  20. return prod;
  21. }
  22. }
  23. double powerD(double exp, double base){
  24. if(absD(exp) - ((int) absD(exp)) < 0.000001){
  25. if(exp>=0.0){
  26. return p(exp, base);
  27. }
  28. else{
  29. if (base == 0.0){
  30. return -1.0;
  31. }
  32. return (1.0 / p((exp*-1), base));
  33. }
  34. }else if(base > 0.0){
  35. if(exp>=0.0){
  36. return exponential(exp*logN(base));
  37. }
  38. else{
  39. if (base == 0.0){
  40. return -1.0;
  41. }
  42. return (1.0 / exponential((-1*exp)*logN(base)));
  43. }
  44. }
  45. return -1.0;
  46. }
  47. unsigned long long fac(int x){
  48. unsigned long long prod = 1;
  49. if(x==0) return 1;
  50. for (int i = 1; i <= x; i++){
  51. if (prod > ULLONG_MAX / i){
  52. break;
  53. }
  54. prod*=i;
  55. }
  56. return prod;
  57. }
  58. double exponential(double x){
  59. double sum = 0.0;
  60. for(int i = 0; i<=21; i++){
  61. sum += (1.0/fac(i)*(powerD(i,x)));
  62. }
  63. return sum;
  64. }