diff options
author | Guido van Rossum <guido@python.org> | 2001-08-08 05:00:18 (GMT) |
---|---|---|
committer | Guido van Rossum <guido@python.org> | 2001-08-08 05:00:18 (GMT) |
commit | 4668b000a1d9113394941ad39875c827634feb49 (patch) | |
tree | 734560442fef1ce34912ceb772099b9a006e010a /Objects/classobject.c | |
parent | 074c9d2b2081237c1071a3775f6e36252cf16ad7 (diff) | |
download | cpython-4668b000a1d9113394941ad39875c827634feb49.zip cpython-4668b000a1d9113394941ad39875c827634feb49.tar.gz cpython-4668b000a1d9113394941ad39875c827634feb49.tar.bz2 |
Implement PEP 238 in its (almost) full glory.
This introduces:
- A new operator // that means floor division (the kind of division
where 1/2 is 0).
- The "future division" statement ("from __future__ import division)
which changes the meaning of the / operator to implement "true
division" (where 1/2 is 0.5).
- New overloadable operators __truediv__ and __floordiv__.
- New slots in the PyNumberMethods struct for true and floor division,
new abstract APIs for them, new opcodes, and so on.
I emphasize that without the future division statement, the semantics
of / will remain unchanged until Python 3.0.
Not yet implemented are warnings (default off) when / is used with int
or long arguments.
This has been on display since 7/31 as SF patch #443474.
Flames to /dev/null.
Diffstat (limited to 'Objects/classobject.c')
-rw-r--r-- | Objects/classobject.c | 8 |
1 files changed, 8 insertions, 0 deletions
diff --git a/Objects/classobject.c b/Objects/classobject.c index 4bad2fd..9c01538 100644 --- a/Objects/classobject.c +++ b/Objects/classobject.c @@ -1435,6 +1435,8 @@ BINARY(instance_mul, "mul", PyNumber_Multiply) BINARY(instance_div, "div", PyNumber_Divide) BINARY(instance_mod, "mod", PyNumber_Remainder) BINARY(instance_divmod, "divmod", PyNumber_Divmod) +BINARY(instance_floordiv, "floordiv", PyNumber_FloorDivide) +BINARY(instance_truediv, "truediv", PyNumber_TrueDivide) BINARY_INPLACE(instance_ior, "or", PyNumber_InPlaceOr) BINARY_INPLACE(instance_ixor, "xor", PyNumber_InPlaceXor) @@ -1446,6 +1448,8 @@ BINARY_INPLACE(instance_isub, "sub", PyNumber_InPlaceSubtract) BINARY_INPLACE(instance_imul, "mul", PyNumber_InPlaceMultiply) BINARY_INPLACE(instance_idiv, "div", PyNumber_InPlaceDivide) BINARY_INPLACE(instance_imod, "mod", PyNumber_InPlaceRemainder) +BINARY_INPLACE(instance_ifloordiv, "floordiv", PyNumber_InPlaceFloorDivide) +BINARY_INPLACE(instance_itruediv, "truediv", PyNumber_InPlaceTrueDivide) /* Try a 3-way comparison, returning an int; v is an instance. Return: -2 for an exception; @@ -1900,6 +1904,10 @@ static PyNumberMethods instance_as_number = { (binaryfunc)instance_iand, /* nb_inplace_and */ (binaryfunc)instance_ixor, /* nb_inplace_xor */ (binaryfunc)instance_ior, /* nb_inplace_or */ + (binaryfunc)instance_floordiv, /* nb_floor_divide */ + (binaryfunc)instance_truediv, /* nb_true_divide */ + (binaryfunc)instance_ifloordiv, /* nb_inplace_floor_divide */ + (binaryfunc)instance_itruediv, /* nb_inplace_true_divide */ }; PyTypeObject PyInstance_Type = { |