From 2aa87f4522cc39bf638fd5fb658de6f78285afa3 Mon Sep 17 00:00:00 2001 From: Alex Shinn Date: Tue, 7 Jun 2016 22:47:43 +0900 Subject: [PATCH] fixing complex sqrt near branch cut (issue #353) --- bignum.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bignum.c b/bignum.c index b94399cf..972d4638 100644 --- a/bignum.c +++ b/bignum.c @@ -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; }