[Python-checkins] python/dist/src/Lib decimal.py,1.19,1.20

rhettinger at users.sourceforge.net rhettinger at users.sourceforge.net
Sat Aug 7 01:42:20 CEST 2004


Update of /cvsroot/python/python/dist/src/Lib
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv5609

Modified Files:
	decimal.py 
Log Message:
SF bug #1002530:  test_decimal fails if repeated

* Protect the pre-defined contexts by using a deepcopy() instead of copy().
* Micro-optimization:  prefer x&1 over x%2



Index: decimal.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/decimal.py,v
retrieving revision 1.19
retrieving revision 1.20
diff -C2 -d -r1.19 -r1.20
*** decimal.py	14 Jul 2004 21:04:27 -0000	1.19
--- decimal.py	6 Aug 2004 23:42:16 -0000	1.20
***************
*** 393,397 ****
          """Set this thread's context to context."""
          if context in (DefaultContext, BasicContext, ExtendedContext):
!             context = context.copy()
          threading.currentThread().__decimal_context__ = context
  
--- 393,398 ----
          """Set this thread's context to context."""
          if context in (DefaultContext, BasicContext, ExtendedContext):
!             context = copy.deepcopy(context)
!             context.clear_flags()
          threading.currentThread().__decimal_context__ = context
  
***************
*** 431,435 ****
          """Set this thread's context to context."""
          if context in (DefaultContext, BasicContext, ExtendedContext):
!             context = context.copy()
          _local.__decimal_context__ = context
  
--- 432,437 ----
          """Set this thread's context to context."""
          if context in (DefaultContext, BasicContext, ExtendedContext):
!             context = copy.deepcopy(context)
!             context.clear_flags()
          _local.__decimal_context__ = context
  
***************
*** 1635,1639 ****
                      break
          if half:
!             if self._int[prec-1] %2 == 0:
                  return tmp
          return self._round_half_up(prec, expdiff, context, tmp)
--- 1637,1641 ----
                      break
          if half:
!             if self._int[prec-1] & 1 == 0:
                  return tmp
          return self._round_half_up(prec, expdiff, context, tmp)
***************
*** 1931,1935 ****
  
          expadd = tmp._exp / 2
!         if tmp._exp % 2 == 1:
              tmp._int += (0,)
              tmp._exp = 0
--- 1933,1937 ----
  
          expadd = tmp._exp / 2
!         if tmp._exp & 1:
              tmp._int += (0,)
              tmp._exp = 0
***************
*** 1941,1945 ****
          firstprec = context.prec
          context.prec = 3
!         if tmp.adjusted() % 2 == 0:
              ans = Decimal( (0, (8,1,9), tmp.adjusted()  - 2) )
              ans = ans.__add__(tmp.__mul__(Decimal((0, (2,5,9), -2)),
--- 1943,1947 ----
          firstprec = context.prec
          context.prec = 3
!         if tmp.adjusted() & 1 == 0:
              ans = Decimal( (0, (8,1,9), tmp.adjusted()  - 2) )
              ans = ans.__add__(tmp.__mul__(Decimal((0, (2,5,9), -2)),
***************
*** 2076,2080 ****
          if self._exp > 0:
              return 1
!         return self._int[-1+self._exp] % 2 == 0
  
      def adjusted(self):
--- 2078,2082 ----
          if self._exp > 0:
              return 1
!         return self._int[-1+self._exp] & 1 == 0
  
      def adjusted(self):



More information about the Python-checkins mailing list