[Python-checkins] r75569 - sandbox/trunk/decimal/decimal_in_c/decimal.py

mark.dickinson python-checkins at python.org
Tue Oct 20 16:40:36 CEST 2009


Author: mark.dickinson
Date: Tue Oct 20 16:40:35 2009
New Revision: 75569

Log:
Make int(NaN) raise ValueError;  optimize int to use Deccoeff shifts

Modified:
   sandbox/trunk/decimal/decimal_in_c/decimal.py

Modified: sandbox/trunk/decimal/decimal_in_c/decimal.py
==============================================================================
--- sandbox/trunk/decimal/decimal_in_c/decimal.py	(original)
+++ sandbox/trunk/decimal/decimal_in_c/decimal.py	Tue Oct 20 16:40:35 2009
@@ -1617,18 +1617,17 @@
         """Converts self to an int, truncating if necessary."""
         if self._is_special:
             if self.is_nan():
-                context = getcontext()
-                # XXX this makes no sense:  why InvalidContext?
-                return context._raise_error(InvalidContext)
+                raise ValueError("Cannot convert NaN to integer")
             elif self.is_infinite():
                 raise OverflowError("Cannot convert infinity to long")
         if not self:
             return 0
         s = (-1)**self._sign
         if self._exp >= 0:
-            return s*int(str(self._int) or '0')*10**self._exp
+            return s*int(self._int << self._exp)
         else:
-            return s*int(str(self._int)[:self._exp] or '0')
+            # exponent less than zero;  so just shift
+            return s*int(self._int >> -self._exp)
 
     __trunc__ = __int__
 


More information about the Python-checkins mailing list