Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public static double sin(double x, double eps) {
- double sum = 0;
- double lastD = -Integer.MAX_VALUE;
- double a = -1;
- double b = x;
- double c = 1;
- double d;
- for (int n = 0; true; n++) {
- a = -a;
- if (n != 0) {
- b *= x*x;
- c *= (2*n*(2*n+1));
- }
- d = b / c;
- if (Math.abs(d - lastD) < eps) break;
- lastD = d;
- sum += a*d;
- }
- return sum;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement