fixing complex sqrt near branch cut (issue #353)

This commit is contained in:
Alex Shinn 2016-06-07 22:47:43 +09:00
parent f5c47c467d
commit 2aa87f4522

View file

@ -978,7 +978,7 @@ sexp sexp_complex_sqrt (sexp ctx, sexp z) {
r = sqrt(x*x + y*y);
res = sexp_make_complex(ctx, SEXP_ZERO, SEXP_ZERO);
sexp_complex_real(res) = sexp_make_flonum(ctx, sqrt((x+r)/2));
sexp_complex_imag(res) = sexp_make_flonum(ctx, (y<0?-1:1)*sqrt((-x+r)/2));
sexp_complex_imag(res) = sexp_make_flonum(ctx, ((y<0||(y==0&&1/y<0))?-1:1)*sqrt((-x+r)/2));
sexp_gc_release1(ctx);
return res;
}