sqrt incorrect for exceptional values?
Kahan's paper (Branch Cuts for Elementary Functions) gives an algorithm for the complex square root and mentions the following special cases:
- sqrt(-beta +/- i0) = +0 +/- sqrt(beta), beta >= 0
- sqrt(x +/- i inf) = +inf +/- i inf for all finite x
- sqrt(NaN + i beta) = NaN + i NaN
- sqrt(beta + i NaN) = NaN + i NaN
- sqrt(NaN + i NaN) = NaN + i NaN
- sqrt(inf +/- i beta) = +inf +/- i0
- sqrt(inf +/- i NaN) = +inf + i NaN
- sqrt(-inf +/- i beta) = +0 +/- i inf
- sqrt(-inf +/- i NaN) = NaN +/- i inf
Our implementation of sqrt doesn't satisfy these cases:
-
(sqrt (complex 4 ext:double-float-negative-infinity))
=#C(#.EXT:DOUBLE-FLOAT-POSITIVE-INFINITY #.EXT:DOUBLE-FLOAT-NEGATIVE-INFINITY)
-
(sqrt (complex ext:double-float-negative-infinity *nan*))
=#C(#<DOUBLE-FLOAT Quiet NaN> #.EXT:DOUBLE-FLOAT-NEGATIVE-INFINITY)
-
(sqrt (complex ext:double-float-negative-infinity (- *nan*)))
=#C(#<DOUBLE-FLOAT Quiet NaN> #.EXT:DOUBLE-FLOAT-POSITIVE-INFINITY)
We should fix these and add tests for these cases.