[Python-checkins] CVS: python/nondist/peps pep-0238.txt,1.6,1.7
Guido van Rossum
gvanrossum@users.sourceforge.net
Wed, 25 Jul 2001 09:51:30 -0700
Update of /cvsroot/python/python/nondist/peps
In directory usw-pr-cvs1:/tmp/cvs-serv24781
Modified Files:
pep-0238.txt
Log Message:
Updates by Moshe to match the patch; grab co-authorship.
I'll be reworking this to reflect the discussion in the newsgroup
next.
Index: pep-0238.txt
===================================================================
RCS file: /cvsroot/python/python/nondist/peps/pep-0238.txt,v
retrieving revision 1.6
retrieving revision 1.7
diff -C2 -d -r1.6 -r1.7
*** pep-0238.txt 2001/07/22 15:03:26 1.6
--- pep-0238.txt 2001/07/25 16:51:27 1.7
***************
*** 2,6 ****
Title: Non-integer Division
Version: $Revision$
! Author: pep@zadka.site.co.il (Moshe Zadka)
Status: Draft
Type: Standards Track
--- 2,6 ----
Title: Non-integer Division
Version: $Revision$
! Author: pep@zadka.site.co.il (Moshe Zadka), guido@python.org (Guido van Rossum)
Status: Draft
Type: Standards Track
***************
*** 46,50 ****
Except that the type of a//b will be the type a and b will be
coerced into. Specifically, if a and b are of the same type, a//b
! will be of that type too.
--- 46,53 ----
Except that the type of a//b will be the type a and b will be
coerced into. Specifically, if a and b are of the same type, a//b
! will be of that type too. In the current Python 2.2 implementation,
! this is implemented via the BINARY_INTDIVIDE opcode, and currently
! does the right thing only for ints and longs (and other extension types
! which behave like integers).
***************
*** 65,89 ****
The type of a/b will be either a float or a rational, depending on
! other PEPs[2, 3].
__future__
! A special opcode, FUTURE_DIV will be added that does the
! equivalent of:
! if type(a) in (types.IntType, types.LongType):
! if type(b) in (types.IntType, types.LongType):
! if a % b != 0:
! return float(a)/b
! return a/b
! (or rational(a)/b, depending on whether 0.5 is rational or float).
! If "from __future__ import non_integer_division" is present in the
! module, until the IntType nb_divide is changed, the "/" operator
! is compiled to FUTURE_DIV.
! This is not yet implemented in the Python 2.2 release.
--- 68,100 ----
The type of a/b will be either a float or a rational, depending on
! other PEPs[2, 3]. However, the result will be integral in all case
! the division has no remainder. This will not implemented in Python 2.2.
__future__
! See PEP 236[4] for the __future__ specific rules.
! If "from __future__ import division" is present in the
! module, until the IntType nb_divide is changed, the "/" operator
! is compiled to add 0.0 to the divisor before doing the division.
! This is not exactly the same as what will happen in the future,
! since in the future, the result will be integral when it can.
! This is done via the BINARY_FLOATDIVIDE opcode.
! In Python 2.2, unless the __future__ statement is present,
! the '/' operator is compiled to DIVISION opcode, which is the
! same
!
! C API
! There are four new C-level functions. PyNumber_IntDivide and
! PyNumber_FloatDivide correspond to the // operator and
! the / operator with __future__ statement, respectively.
! PyNumber_InPlaceIntDivide and PyNumber_InPlaceIntDivide correspond
! to the //= operator and to the /= operator with __future__ statement
! respectively. Please refer to the discussion of the operator
! for specification of these functions' behavior.
***************
*** 105,110 ****
spec, but close enough except for the lack of a warning for
truncated results from old division) is available from the
! SourceForge patch manager:
! http://sourceforge.net/tracker/index.php?func=detail&aid=443474&group_id=5470&atid=305470
--- 116,120 ----
spec, but close enough except for the lack of a warning for
truncated results from old division) is available from the
! SourceForge patch manager[5]
***************
*** 119,122 ****
--- 129,138 ----
[3] PEP 240, Adding a Rational Literal to Python, Zadka,
http://www.python.org/peps/pep-0240.html
+
+ [4] PEP 236, Back to the __future__, Peters,
+ http://www.python.org/peps/pep-0236.html
+
+ [5] Patch 443474, from __future__ import division
+ http://sourceforge.net/tracker/index.php?func=detail&aid=443474&group_id=5470&atid=305470