mirror of
https://github.com/ashinn/chibi-scheme.git
synced 2025-05-18 21:29:19 +02:00
fix sqrt of complex negative zero (issue #785)
This commit is contained in:
parent
bf881b3e61
commit
1f0f07114b
2 changed files with 2 additions and 1 deletions
2
bignum.c
2
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;
|
||||
}
|
||||
|
|
|
@ -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))
|
||||
|
|
Loading…
Add table
Reference in a new issue