[Patches] [ python-Patches-443474 ] from __future__ import division

noreply@sourceforge.net noreply@sourceforge.net
Tue, 07 Aug 2001 22:04:18 -0700


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

Category: Parser/Compiler
Group: None
>Status: Closed
>Resolution: Accepted
Priority: 5
Submitted By: Guido van Rossum (gvanrossum)
Assigned to: Nobody/Anonymous (nobody)
Summary: from __future__ import division

Initial Comment:
This patch is a quick hack to implement one way of
doing PEP 238 (non-integer division).

There are two parts to it.

Part 1: the // operator implements integer division.

Part 2: when "from __future__ import division" is
in effect, the / operator implements float division.

The //= and /= operators are also affected.
(This is part of why I chose // over the keyword 'div';
also because that would require a new keyword.)

The implementation now has three division operations
(of each variation: regular and inplace, and
corresponding opcodes) where it used to have one:

- Division for / without future statement
- FloatDivision for / with future statement
- IntDivision for //

The actual implementations for IntDivision and
FloatDivision are a bit lame:

- (old) Division is unchanged (using nb_division)
- IntDivision just calls Division, so only does the
  right thing for ints and longs
- FloatDivision adds 0.0 to the second operand

At some point in the future, to keep NumPy happy,
the "as number" struct should grow extra slots
for the additional operations, and the above
operations should only be used as fallbacks.
(Maybe the fallback for IntDivision should use
the nb_divmod slot as fallback.)

Enjoy!

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

Comment By: Guido van Rossum (gvanrossum)
Date: 2001-07-31 12:33

Message:
Logged In: YES 
user_id=6380

Uploading a new version.  This includes the patch for graminit.c.
This follows the revised PEP: terminology changed to true and floor division,
actual slots in type objects used.

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

Comment By: Guido van Rossum (gvanrossum)
Date: 2001-07-21 21:39

Message:
Logged In: YES 
user_id=6380

Note, the patch doesn't include the changes for graminit.c
(because they were big).  This may cause problems on
Windows, where that file is not automatically recreated when
the grammar changes.

I'm including the new graminit.c just in case.  (graminit.h
is unchanged.)

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

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