[Patches] [ python-Patches-440487 ] int to the negative power -> float

noreply@sourceforge.net noreply@sourceforge.net
Wed, 11 Jul 2001 16:18:06 -0700


Patches item #440487, was opened at 2001-07-11 12:27
You can respond by visiting: 
http://sourceforge.net/tracker/?func=detail&atid=305470&aid=440487&group_id=5470

Category: core (C code)
Group: None
Status: Open
Resolution: None
Priority: 5
Submitted By: Guido van Rossum (gvanrossum)
>Assigned to: Tim Peters (tim_one)
Summary: int to the negative power -> float

Initial Comment:
Currently, int to the negative int power raises an
exception.

This was one of the two problems that the VPython users
complained about. (The other was that integer division
returns a truncated integer, but that's another story.
:-)

I propose to implement this in Python 2.2.  Anybody
have a problem with this?


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

>Comment By: Guido van Rossum (gvanrossum)
Date: 2001-07-11 16:18

Message:
Logged In: YES 
user_id=6380

OK, here's a new patch, for int and long.

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

Comment By: Tim Peters (tim_one)
Date: 2001-07-11 14:46

Message:
Logged In: YES 
user_id=31435

Back to Guido.

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

Comment By: Tim Peters (tim_one)
Date: 2001-07-11 13:23

Message:
Logged In: YES 
user_id=31435

I liked the first patch better.  *Looks* like under the new 
patch

pow(2, -3, 1)

will raise a ValueError but

2 ** -3 % 1

will return 0.125.  That's close to inexplicable.

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

Comment By: Tim Peters (tim_one)
Date: 2001-07-11 13:04

Message:
Logged In: YES 
user_id=31435

Tough luck for you, you mean <wink>.

I considered z != None and didn't care.  They're going to 
be just as surprised by i**j returning a float if j 
accidentally becomes negative.  When making a formerly 
exceptional case "mean something", potential surprise is 
unavoidable, and if in the new world

2 ** -3 % 1

returns

0.125

is will be just as surprising if

pow(2, -3, 1)

does not return 0.125.  The new rules should be consistent 
with *themselves* more than with oddball cases across 
releases.

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

Comment By: Guido van Rossum (gvanrossum)
Date: 2001-07-11 12:59

Message:
Logged In: YES 
user_id=6380

New patch that only falls back to float when 3rd arg is
None.

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

Comment By: Guido van Rossum (gvanrossum)
Date: 2001-07-11 12:52

Message:
Logged In: YES 
user_id=6380

Tough luck. :-)

There may be something else wrong with the patch: it
probably shouldn't fall back to float when z is not None.
After all, pow(x, y, z) should compute x**y % z, and I'm
sure that someone using this would be quite surprised to get
a floating point number back if they accidentally let y
become negative!

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

Comment By: Tim Peters (tim_one)
Date: 2001-07-11 12:46

Message:
Logged In: YES 
user_id=31435

No objection so far as it goes, but surely long_pow() 
should also attempt the same kind of thing then.  Should 
add some test cases and docs too (yes, I'm going to hold 
you to the same stds as contributors <wink>).


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

You can respond by visiting: 
http://sourceforge.net/tracker/?func=detail&atid=305470&aid=440487&group_id=5470