diff --git a/bignum.c b/bignum.c index 266cd933..93a765f5 100644 --- a/bignum.c +++ b/bignum.c @@ -1110,7 +1110,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||(y==0&&1/y<0))?-1:1)*sqrt((-x+r)/2)); + sexp_complex_imag(res) = sexp_make_flonum(ctx, ((y<-0.0)?-1:1)*sqrt((-x+r)/2)); sexp_gc_release1(ctx); return res; } diff --git a/tests/r7rs-tests.scm b/tests/r7rs-tests.scm index 01772232..f07e1c10 100644 --- a/tests/r7rs-tests.scm +++ b/tests/r7rs-tests.scm @@ -994,6 +994,7 @@ (test 3.0 (inexact (sqrt 9))) (test 1.4142135623731 (sqrt 2)) (test 0.0+1.0i (inexact (sqrt -1))) +(test 0.0+1.0i (sqrt -1.0-0.0i)) (test '(2 0) (call-with-values (lambda () (exact-integer-sqrt 4)) list)) (test '(2 1) (call-with-values (lambda () (exact-integer-sqrt 5)) list))