// Integrating -log(1-x)/x once around branch point at 1. #include #include #include #include typedef double _Complex C; typedef double R; static R sq(R x){return x*x;} static R m2(C x){return sq(creal(x)) + sq(cimag(x));} static void pc(C a){printf("%20.16f + %19.16fi\n", creal(a), cimag(a));} C c(R x, R y){C a; __real__ a = x; __imag__ a = y; return a;} static R const tp = 2*3.141592653589793238; static int const N = 100000; static C mem; C ln(C z){ static int n = 0; if(m2(z - mem) > 0.001) {pc(z); pc(mem); exit(printf("ouch\n"));} if(creal(z) < 0 && (cimag(z)<0) != (cimag(mem)<0)) n += cimag(z)<0?1:-1; mem = z; return clog(z) + c(0, n*tp);} int main(){mem = 1; if(0) {printf("ln(-1+0.01i) = "); pc(clog(-1+0.01i)); printf("ln(-1-0.01i) = "); pc(clog(-1-0.01i)); {int j; for(j=0; j<400; ++j) {R t = -0.01*j; C v = ln(c(cos(t), sin(t))); if(j>300) {printf("%d", j); pc(v);}}}} else {C s = 0; int j; for(j=0; j