[Python-bugs-list] [ python-Bugs-649187 ] sqrt(-1) weirdness?

noreply@sourceforge.net noreply@sourceforge.net
Thu, 05 Dec 2002 14:51:06 -0800


Bugs item #649187, was opened at 2002-12-05 22:26
You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=649187&group_id=5470

Category: Python Library
Group: Python 2.2
>Status: Closed
>Resolution: Invalid
Priority: 5
Submitted By: H. Richard Harkins (hrharkins)
Assigned to: Nobody/Anonymous (nobody)
Summary: sqrt(-1) weirdness?

Initial Comment:
I was justing playing around with some complex number
stuff for kicks and ran across something I'm not sure
about, not having playing with complex numbers for any
real purpose for so long.  Anyway, here's the scenario:

>>> from math import sqrt
>>> sqrt(-1)
(Produces a ValueError)
>>> -1 ** .5
-1.0

Shouldn't each of these produce (0+1j)?  If not,
shouldn't the second case produce ValueError too?  It
should be the case that -1.0 ** 2 == -1.0 ** .5,
shouldn't it?

Rich


----------------------------------------------------------------------

>Comment By: Neil Schemenauer (nascheme)
Date: 2002-12-05 22:51

Message:
Logged In: YES 
user_id=35752

Not a bug.  Try:

  (-1)**2

Regarding sqrt(-1), use:

  import cmath
  cmath.sqrt(-1)





----------------------------------------------------------------------

Comment By: H. Richard Harkins (hrharkins)
Date: 2002-12-05 22:30

Message:
Logged In: YES 
user_id=283299

Okay, even weirder.  Just tested my assertion above and
Python says it's true!

>>> -1.0 ** 2
-1.0

I just noticed Perl doing the same thing in this case.  What
gives here?  Is this a libc library problem?  (This is under
RedHat 8 Linux kernel 2.4.18-14).


----------------------------------------------------------------------

You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=649187&group_id=5470