power TypeErrors

Brad Hards bhards at bigpond.net.au
Tue Nov 5 16:10:28 EST 2002


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On Wed, 6 Nov 2002 08:02, anton wilson wrote:
> I'm trying to understand the possible type errors for **
>
> The language reference states that
>
>
> The power operator has the same semantics as the built-in pow() function,
> when called with two arguments: it yields its left argument raised to the
> power of its right argument. The numeric arguments are first converted to a
> common type. The result type is that of the arguments after coercion; if
> the result is not expressible in that type (as in raising an integer to a
> negative power, or a negative floating point number to a broken power), a
> TypeError exception is raised.
Looks like the docs are outdated. I'm not sure about the "broken power" bit.

[bradh at localhost USB-guide-head]$ python
Python 1.5.2 (#1, Jul  5 2001, 03:02:19)  [GCC 2.96 20000731 (Red Hat Linux 
7.1 2 on linux-i386
Copyright 1991-1995 Stichting Mathematisch Centrum, Amsterdam
>>> 1**-2
Traceback (innermost last):
  File "<stdin>", line 1, in ?
ValueError: integer to the negative power
>>> -1.2**0.5
- -1.09544511501

bradh at squirt python $ python
Python 2.2.1 (#1, Oct  4 2002, 09:50:49)
[GCC 2.95.3 20010315 (release)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> 1**-2
1.0
>>> -1.2 ** 0.5
- -1.0954451150103321

Brad
- -- 
http://linux.conf.au. 22-25Jan2003. Perth, Aust. I'm registered. Are you?
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.0.6 (GNU/Linux)
Comment: For info see http://www.gnupg.org

iD8DBQE9yDPEW6pHgIdAuOMRAjdTAKCDtA6nJWu5JsuWHRws+URhIxZbggCfVqjG
noMdw5mMvn0VMAQ0SILvCOc=
=eq55
-----END PGP SIGNATURE-----





More information about the Python-list mailing list