fix `sqrt' on numbers with negative real and inexact-zero imag

Closes PR 13028
This commit is contained in:
Matthew Flatt 2012-08-16 04:43:19 -06:00
parent 315834f097
commit 65588b156b
2 changed files with 18 additions and 2 deletions

View File

@ -1671,6 +1671,10 @@
(test (make-rectangular 0 (expt 5 13)) sqrt (- (expt 5 26)))
(test (make-rectangular 0 545915034.0) z-round (sqrt (- (expt 5 25))))
(test 0.0+1.0i sqrt -1.0+0.0i)
(test 0.0f0+1.0f0i sqrt -1.0f0+0.0f0i)
(test 0.0+0.0i sqrt 0.0+0.0i)
(err/rt-test (sqrt "a"))
(arity-test sqrt 1 1)

View File

@ -356,8 +356,20 @@ Scheme_Object *scheme_complex_sqrt(const Scheme_Object *o)
r = scheme_sqrt(1, &r);
if (!SCHEME_COMPLEXP(r))
return scheme_make_complex(r, i);
else
return r;
else {
c = (Scheme_Complex *)r;
if (SAME_OBJ(c->r, zero)) {
/* need an inexact-zero real part: */
#ifdef MZ_USE_SINGLE_FLOATS
if (SCHEME_FLTP(c->i))
r = scheme_make_float(0.0);
else
#endif
r = scheme_make_double(0.0);
return scheme_make_complex(r, c->i);
} else
return r;
}
}
ssq = scheme_bin_plus(scheme_bin_mult(r, r),