# Should numpy.sqrt(-1) return 1j rather than?nan?

Stefan van der Walt stefan at sun.ac.za
Thu Oct 12 11:14:50 CDT 2006

```On Thu, Oct 12, 2006 at 10:53:12AM -0400, Alan G Isaac wrote:
> On Thu, 12 Oct 2006, Stefan van der Walt apparently wrote:
> > I tried to explain the argument at
> > http://www.scipy.org/NegativeSquareRoot
>
> Helpful.  But you start off by saying:
>         In mathematics, the above assumption is true -- that
>         the square root of -1 is 1j.
>
> Since square root is (here) a function, and part of the
> function definition is the domain and codomain, this
> statement is not correct.  If the codomain is real numbers,
> the domain must correspondingly be (a subset of) the
> nonnegative reals.  The nan output is the result of an
> **invalid** input.
>
> So the question is really: "Why is a negative real number an
> invalid input in this implementation", or "Why in this
> implementation is the type of the output restricted by the
> type of the input?" You get a good start on answering that.

You are more than welcome to change the wiki if you can think of a
simpler way to explain the problem... In fact, I would encourage that
-- I just put it there as a starting point.

Cheers
Stéfan

-------------------------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier