fork(3) download
  1. #include <iostream>
  2. #include <math.h>
  3. #include <iomanip>
  4. #include <limits>
  5.  
  6. using namespace std;
  7.  
  8. double f_tan(double i);
  9. double f_sin_2(double i);
  10. double f_sin(double i);
  11. double add_phase(double x, double phase = M_PI_2);
  12.  
  13. int main() {
  14.  
  15. int numb_of_loop = 5;
  16.  
  17. double shift = 0;
  18. double shift_step = 0.01;
  19. for (int j=0; j < 3*numb_of_loop; j++ ) {
  20. for (int i=0; i < numb_of_loop; i++ ) {
  21. cout << "tan(x) = " << f_tan(i + shift) << std::setw(17)
  22. << "sin(x)^2 = " << f_sin_2(i + shift) << std::setw(17)
  23. << "sin(x)/x = " << f_sin(i+shift) << endl;
  24. }
  25.  
  26. cout << "----------------------" << endl;
  27. shift = shift + shift_step;
  28. }
  29.  
  30. return 0;
  31. }
  32.  
  33.  
  34. double f_tan(double i) {
  35. double x = add_phase(i*M_PI,M_PI_4);
  36. if (cos(x) == 0) {
  37. return std::numeric_limits<double>::infinity();
  38. }
  39. return tan(x);
  40. }
  41.  
  42. double f_sin_2(double i) {
  43. double x = add_phase(i*M_PI);
  44. double y = sin(x);
  45. return y*y;
  46. }
  47.  
  48. double f_sin(double i) {
  49. double x = add_phase(i*2*M_PI,M_PI_4);
  50. if (x < 0.00001) {
  51. return std::numeric_limits<double>::infinity();
  52. }
  53. return sin(x)/x;
  54. }
  55.  
  56. double add_phase(double x, double phase) {
  57. return x + phase;
  58. }
  59.  
Success #stdin #stdout 0s 3340KB
stdin
Standard input is empty
stdout
tan(x) = 1      sin(x)^2 = 1      sin(x)/x = 0.900316
tan(x) = 1      sin(x)^2 = 1      sin(x)/x = 0.100035
tan(x) = 1      sin(x)^2 = 1      sin(x)/x = 0.0529598
tan(x) = 1      sin(x)^2 = 1      sin(x)/x = 0.0360127
tan(x) = 1      sin(x)^2 = 1      sin(x)/x = 0.0272823
----------------------
tan(x) = 1.06489      sin(x)^2 = 0.999013      sin(x)/x = 0.884325
tan(x) = 1.06489      sin(x)^2 = 0.999013      sin(x)/x = 0.105184
tan(x) = 1.06489      sin(x)^2 = 0.999013      sin(x)/x = 0.0559175
tan(x) = 1.06489      sin(x)^2 = 0.999013      sin(x)/x = 0.038081
tan(x) = 1.06489      sin(x)^2 = 0.999013      sin(x)/x = 0.0288716
----------------------
tan(x) = 1.13428      sin(x)^2 = 0.996057      sin(x)/x = 0.86729
tan(x) = 1.13428      sin(x)^2 = 0.996057      sin(x)/x = 0.109832
tan(x) = 1.13428      sin(x)^2 = 0.996057      sin(x)/x = 0.058628
tan(x) = 1.13428      sin(x)^2 = 0.996057      sin(x)/x = 0.0399864
tan(x) = 1.13428      sin(x)^2 = 0.996057      sin(x)/x = 0.0303395
----------------------
tan(x) = 1.20879      sin(x)^2 = 0.991144      sin(x)/x = 0.849251
tan(x) = 1.20879      sin(x)^2 = 0.991144      sin(x)/x = 0.113969
tan(x) = 1.20879      sin(x)^2 = 0.991144      sin(x)/x = 0.061083
tan(x) = 1.20879      sin(x)^2 = 0.991144      sin(x)/x = 0.0417223
tan(x) = 1.20879      sin(x)^2 = 0.991144      sin(x)/x = 0.0316809
----------------------
tan(x) = 1.28919      sin(x)^2 = 0.984292      sin(x)/x = 0.830251
tan(x) = 1.28919      sin(x)^2 = 0.984292      sin(x)/x = 0.117589
tan(x) = 1.28919      sin(x)^2 = 0.984292      sin(x)/x = 0.0632754
tan(x) = 1.28919      sin(x)^2 = 0.984292      sin(x)/x = 0.0432832
tan(x) = 1.28919      sin(x)^2 = 0.984292      sin(x)/x = 0.0328911
----------------------
tan(x) = 1.37638      sin(x)^2 = 0.975528      sin(x)/x = 0.810332
tan(x) = 1.37638      sin(x)^2 = 0.975528      sin(x)/x = 0.120688
tan(x) = 1.37638      sin(x)^2 = 0.975528      sin(x)/x = 0.0651991
tan(x) = 1.37638      sin(x)^2 = 0.975528      sin(x)/x = 0.044664
tan(x) = 1.37638      sin(x)^2 = 0.975528      sin(x)/x = 0.033966
----------------------
tan(x) = 1.47146      sin(x)^2 = 0.964888      sin(x)/x = 0.789542
tan(x) = 1.47146      sin(x)^2 = 0.964888      sin(x)/x = 0.123262
tan(x) = 1.47146      sin(x)^2 = 0.964888      sin(x)/x = 0.0668491
tan(x) = 1.47146      sin(x)^2 = 0.964888      sin(x)/x = 0.0458603
tan(x) = 1.47146      sin(x)^2 = 0.964888      sin(x)/x = 0.0349021
----------------------
tan(x) = 1.57575      sin(x)^2 = 0.952414      sin(x)/x = 0.767927
tan(x) = 1.57575      sin(x)^2 = 0.952414      sin(x)/x = 0.12531
tan(x) = 1.57575      sin(x)^2 = 0.952414      sin(x)/x = 0.0682213
tan(x) = 1.57575      sin(x)^2 = 0.952414      sin(x)/x = 0.0468688
tan(x) = 1.57575      sin(x)^2 = 0.952414      sin(x)/x = 0.0356963
----------------------
tan(x) = 1.69091      sin(x)^2 = 0.938153      sin(x)/x = 0.745539
tan(x) = 1.69091      sin(x)^2 = 0.938153      sin(x)/x = 0.126834
tan(x) = 1.69091      sin(x)^2 = 0.938153      sin(x)/x = 0.0693131
tan(x) = 1.69091      sin(x)^2 = 0.938153      sin(x)/x = 0.0476866
tan(x) = 1.69091      sin(x)^2 = 0.938153      sin(x)/x = 0.0363461
----------------------
tan(x) = 1.81899      sin(x)^2 = 0.922164      sin(x)/x = 0.722428
tan(x) = 1.81899      sin(x)^2 = 0.922164      sin(x)/x = 0.127837
tan(x) = 1.81899      sin(x)^2 = 0.922164      sin(x)/x = 0.0701228
tan(x) = 1.81899      sin(x)^2 = 0.922164      sin(x)/x = 0.0483117
tan(x) = 1.81899      sin(x)^2 = 0.922164      sin(x)/x = 0.0368498
----------------------
tan(x) = 1.96261      sin(x)^2 = 0.904508      sin(x)/x = 0.698647
tan(x) = 1.96261      sin(x)^2 = 0.904508      sin(x)/x = 0.128323
tan(x) = 1.96261      sin(x)^2 = 0.904508      sin(x)/x = 0.0706497
tan(x) = 1.96261      sin(x)^2 = 0.904508      sin(x)/x = 0.0487428
tan(x) = 1.96261      sin(x)^2 = 0.904508      sin(x)/x = 0.037206
----------------------
tan(x) = 2.12511      sin(x)^2 = 0.885257      sin(x)/x = 0.674249
tan(x) = 2.12511      sin(x)^2 = 0.885257      sin(x)/x = 0.128298
tan(x) = 2.12511      sin(x)^2 = 0.885257      sin(x)/x = 0.0708942
tan(x) = 2.12511      sin(x)^2 = 0.885257      sin(x)/x = 0.0489795
tan(x) = 2.12511      sin(x)^2 = 0.885257      sin(x)/x = 0.0374141
----------------------
tan(x) = 2.31086      sin(x)^2 = 0.864484      sin(x)/x = 0.649291
tan(x) = 2.31086      sin(x)^2 = 0.864484      sin(x)/x = 0.127772
tan(x) = 2.31086      sin(x)^2 = 0.864484      sin(x)/x = 0.0708581
tan(x) = 2.31086      sin(x)^2 = 0.864484      sin(x)/x = 0.049022
tan(x) = 2.31086      sin(x)^2 = 0.864484      sin(x)/x = 0.0374738
----------------------
tan(x) = 2.52571      sin(x)^2 = 0.842274      sin(x)/x = 0.623829
tan(x) = 2.52571      sin(x)^2 = 0.842274      sin(x)/x = 0.126754
tan(x) = 2.52571      sin(x)^2 = 0.842274      sin(x)/x = 0.0705439
tan(x) = 2.52571      sin(x)^2 = 0.842274      sin(x)/x = 0.0488714
tan(x) = 2.52571      sin(x)^2 = 0.842274      sin(x)/x = 0.0373858
----------------------
tan(x) = 2.77761      sin(x)^2 = 0.818712      sin(x)/x = 0.597919
tan(x) = 2.77761      sin(x)^2 = 0.818712      sin(x)/x = 0.125256
tan(x) = 2.77761      sin(x)^2 = 0.818712      sin(x)/x = 0.0699552
tan(x) = 2.77761      sin(x)^2 = 0.818712      sin(x)/x = 0.0485294
tan(x) = 2.77761      sin(x)^2 = 0.818712      sin(x)/x = 0.0371509
----------------------