Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- double arctg(double x) {
- assert(fabs(x) <= 1.0);
- if (fabs(x) <= 1) {
- // Zeby nie liczyc tego w kolko
- double xsqr = x*x;
- // Licznik
- double num = x;
- // Mianownik
- double denom = 1.0;
- // Pomocnicza zmienna, dzieki niej
- // oceniamy kiedy sie zatrzymać
- double tmp = 0.0;
- // Suma
- double sum = 0.0;
- do {
- tmp = num/denom;
- sum += tmp;
- num *= -xsqr;
- denom += 2.0;
- }while(fabs(tmp)>1e-5);
- return sum;
- }else {
- return 0.0;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement