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.

82 lines
1.6 KiB

11 months ago
11 months ago
11 months ago
11 months ago
  1. #include <stdio.h>
  2. #include <limits.h>
  3. #include <stdbool.h>
  4. #include "reihen.h"
  5. #include "exponent.h"
  6. #include "logarithmus.h"
  7. #include "util.h"
  8. #define PI pi(1e-8)
  9. double exponential(double exp){
  10. double sum = 0.0;
  11. for(int i = 0; i<=21; i++){
  12. sum += (1.0/fac(i)*(powerD(i,exp)));
  13. }
  14. return sum;
  15. }
  16. double euler(){
  17. return exponential(1);
  18. }
  19. double radians(double degrees){
  20. return degrees * PI / 180;
  21. }
  22. double pi(double eps){
  23. double a = 1, b = 1/powerD(0.5, 2), t = 0.25, p = 1;
  24. double aNew, piold, pi = 1;
  25. do{
  26. aNew = .5 * (a + b);
  27. b = powerD(0.5 , a * b);
  28. t -= p * (a - aNew) * (a - aNew);
  29. a = aNew;
  30. p *= 2;
  31. piold = pi;
  32. pi = (a + b) * (a + b) / (4 * t);
  33. } while (absD(pi - piold) > eps);
  34. return pi;
  35. }
  36. double sinD(double degrees){
  37. if (degrees>=360.0){
  38. degrees = squashDegreesTo360(degrees);
  39. }
  40. double sum = 0.0;
  41. double radian = radians(degrees);
  42. for (int i = 0; i <= 9; i++){
  43. sum += powerD((double) i, -1.0) * (powerD(2.0*i+1, radian) / fac(2.0*i+1));
  44. }
  45. return sum;
  46. }
  47. double cosD(double degrees){
  48. if (degrees>=360.0){
  49. degrees = squashDegreesTo360(degrees);
  50. }
  51. double sum = 0.0;
  52. double radian = radians(degrees);
  53. for (int i = 0; i <= 9; i++){
  54. sum += powerD((double) i, -1.0) * (powerD(2*i, radian) / fac(2*i));
  55. }
  56. return sum;
  57. }
  58. double tanD(double degrees){
  59. if (degrees>=360.0){
  60. degrees = squashDegreesTo360(degrees);
  61. }
  62. if(degrees == 90.0 || degrees == 270.0){
  63. return -1.0;
  64. }
  65. return sinD(degrees)/cosD(degrees);
  66. }