Advertisement
Guest User

Untitled

a guest
Aug 16th, 2011
285
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.62 KB | None | 0 0
  1. double arctg(double x) {
  2.     assert(fabs(x) <= 1.0);
  3.  
  4.     if (fabs(x) <= 1) {
  5.         // Zeby nie liczyc tego w kolko
  6.         double xsqr = x*x;
  7.  
  8.         // Licznik
  9.         double num = x;
  10.  
  11.         // Mianownik
  12.         double denom = 1.0;
  13.  
  14.         // Pomocnicza zmienna, dzieki niej
  15.         // oceniamy kiedy sie zatrzymać
  16.         double tmp = 0.0;
  17.  
  18.         // Suma
  19.         double sum = 0.0;
  20.  
  21.         do {
  22.             tmp = num/denom;
  23.             sum += tmp;
  24.             num *= -xsqr;
  25.             denom += 2.0;
  26.         }while(fabs(tmp)>1e-5);
  27.  
  28.         return sum;
  29.     }else {
  30.         return 0.0;
  31.     }
  32. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement