[Python-checkins] python/nondist/sandbox/decimal Decimal.py, 1.18,
1.19
facundobatista at users.sourceforge.net
facundobatista at users.sourceforge.net
Mon Apr 5 18:07:24 EDT 2004
Update of /cvsroot/python/python/nondist/sandbox/decimal
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv27155
Modified Files:
Decimal.py
Log Message:
Added __r*__ methods. Fixed __sub__.
Index: Decimal.py
===================================================================
RCS file: /cvsroot/python/python/nondist/sandbox/decimal/Decimal.py,v
retrieving revision 1.18
retrieving revision 1.19
diff -C2 -d -r1.18 -r1.19
*** Decimal.py 4 Apr 2004 16:14:25 -0000 1.18
--- Decimal.py 5 Apr 2004 22:07:21 -0000 1.19
***************
*** 96,107 ****
"""
! # 0.7.3 2003.4.04 facundobatista: Added _convert_other method, for implicit
! # constructions, and more checks when constructing from
! # tuples. Fixed __sub__ to modify a copy of the instance.
! # 0.7.2 2003.4.02 facundobatista: Fixed __pow__ to run the example ok. Added
! # from_float method. Fixed isnan to accept empty strings.
! # 0.7.1 2003.3.08 facundobatista: Corrected initial examples
! # 0.7.0 2003.2.28 eprice: More changes. Contexts done nicely, exponent limits
! # 0.6.0 2003.2.24 eprice: Many changes. No exponent limits
# Aahz:
--- 96,112 ----
"""
! # facundobatista:
! # 0.7.4 2003.04.05 Added rdiv, rdivmod, rmod, rpow, rfloordiv special methods.
! # Fixed sub.
! # 0.7.3 2003.04.04 Added _convert_other method, for implicit constructions,
! # and more checks when constructing from tuples. Fixed
! # __sub__ to modify a copy of the instance.
! # 0.7.2 2003.04.02 Fixed __pow__ to run the example ok. Added from_float
! # method. Fixed isnan to accept empty strings.
! # 0.7.1 2003.03.08 Corrected initial examples
!
! # eprice:
! # 0.7.0 2003.2.28 More changes. Contexts done nicely, exponent limits
! # 0.6.0 2003.2.24 Many changes. No exponent limits
# Aahz:
***************
*** 973,977 ****
if context is None:
context = getcontext()
! tmp = self._convert_other(other)
ans = self._check_nans(other, context=context)
--- 978,982 ----
if context is None:
context = getcontext()
! other = self._convert_other(other)
ans = self._check_nans(other, context=context)
***************
*** 982,986 ****
# (-0 - 0 = -0 + (-0) = -0, but -0 + 0 = 0.)
# so we change the sign directly to a copy
! tmp = Decimal(tmp)
tmp._sign = 1-tmp._sign
--- 987,991 ----
# (-0 - 0 = -0 + (-0) = -0, but -0 + 0 = 0.)
# so we change the sign directly to a copy
! tmp = Decimal(other)
tmp._sign = 1-tmp._sign
***************
*** 1282,1287 ****
return ans
! def __rdiv__(self, other):
! raise NotImplementedError
def __divmod__(self, other, context=None):
--- 1287,1295 ----
return ans
! def __rdiv__(self, other, context=None):
! """Swaps self/other and returns __div__."""
! other = self._convert_other(other)
! return other.__div__(self, context=context)
! __rtruediv__ = __rdiv__
def __divmod__(self, other, context=None):
***************
*** 1291,1296 ****
return self._divide(other, 1, context)
! def __rdivmod__(self, other):
! raise NotImplementedError
def __mod__(self, other, context=None):
--- 1299,1306 ----
return self._divide(other, 1, context)
! def __rdivmod__(self, other, context=None):
! """Swaps self/other and returns __divmod__."""
! other = self._convert_other(other)
! return other.__divmod__(self, context=context)
def __mod__(self, other, context=None):
***************
*** 1311,1316 ****
return self._divide(other, 3, context)[1]
! def __rmod__(self, other):
! raise NotImplementedError
def remainder_near(self, other, context=None):
--- 1321,1328 ----
return self._divide(other, 3, context)[1]
! def __rmod__(self, other, context=None):
! """Swaps self/other and returns __mod__."""
! other = self._convert_other(other)
! return other.__mod__(self, context=context)
def remainder_near(self, other, context=None):
***************
*** 1394,1397 ****
--- 1406,1414 ----
return self._divide(other, 2, context)[0]
+ def __rfloordiv__(self, other, context=None):
+ """Swaps self/other and returns __floordiv__."""
+ other = self._convert_other(other)
+ return other.__floordiv__(self, context=context)
+
def __float__(self):
"""Float representation."""
***************
*** 1794,1797 ****
--- 1811,1819 ----
return val
+ def __rpow__(self, other, context=None):
+ """Swaps self/other and returns __pow__."""
+ other = self._convert_other(other)
+ return other.__pow__(self, context=context)
+
def normalize(self, context=None):
"""Normalize- strip trailing 0s, change anything equal to 0 to 0e0"""
More information about the Python-checkins
mailing list