diff options
author | Christian Heimes <christian@cheimes.de> | 2007-12-24 08:52:31 (GMT) |
---|---|---|
committer | Christian Heimes <christian@cheimes.de> | 2007-12-24 08:52:31 (GMT) |
commit | 5fb7c2ad0b59b670898c8b1622ddc37331b5cb9e (patch) | |
tree | ea76cdd3ad8729a67920f7bdb0feee56a1600007 /Lib/decimal.py | |
parent | 81f1130908d0bccdaa701887676688e1ca3bc723 (diff) | |
download | cpython-5fb7c2ad0b59b670898c8b1622ddc37331b5cb9e.zip cpython-5fb7c2ad0b59b670898c8b1622ddc37331b5cb9e.tar.gz cpython-5fb7c2ad0b59b670898c8b1622ddc37331b5cb9e.tar.bz2 |
Merged revisions 59565-59594 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r59568 | facundo.batista | 2007-12-19 13:53:01 +0100 (Wed, 19 Dec 2007) | 3 lines
Some minor cleanups. Thanks Mark Dickinson.
........
r59573 | raymond.hettinger | 2007-12-19 19:13:31 +0100 (Wed, 19 Dec 2007) | 1 line
Fix issue 1661: Flags argument silently ignored in re functions with compiled regexes.
........
r59574 | guido.van.rossum | 2007-12-19 20:41:06 +0100 (Wed, 19 Dec 2007) | 7 lines
Patch #1583 by Adam Olsen.
This adds signal.set_wakeup_fd(fd) which sets a file descriptor to
which a zero byte will be written whenever a C exception handler runs.
I added a simple C API as well, PySignal_SetWakeupFd(fd).
........
r59575 | raymond.hettinger | 2007-12-19 23:14:34 +0100 (Wed, 19 Dec 2007) | 1 line
Bigger range for non-extended opargs.
........
r59576 | guido.van.rossum | 2007-12-19 23:51:13 +0100 (Wed, 19 Dec 2007) | 5 lines
Patch #1549 by Thomas Herve.
This changes the rules for when __hash__ is inherited slightly,
by allowing it to be inherited when one or more of __lt__, __le__,
__gt__, __ge__ are overridden, as long as __eq__ and __ne__ aren't.
........
r59577 | raymond.hettinger | 2007-12-20 02:25:05 +0100 (Thu, 20 Dec 2007) | 1 line
Add comments
........
r59578 | brett.cannon | 2007-12-20 11:09:52 +0100 (Thu, 20 Dec 2007) | 3 lines
Add tests for the warnings module; specifically formatwarning and showwarning.
Still need tests for warn_explicit and simplefilter.
........
r59582 | guido.van.rossum | 2007-12-20 18:28:10 +0100 (Thu, 20 Dec 2007) | 2 lines
Patch #1672 by Joseph Armbruster. Use tempdir() to get a temporary directory.
........
r59584 | georg.brandl | 2007-12-20 22:03:02 +0100 (Thu, 20 Dec 2007) | 2 lines
Fix refleak introduced in r59576.
........
r59586 | guido.van.rossum | 2007-12-21 00:48:28 +0100 (Fri, 21 Dec 2007) | 4 lines
Improve performance of built-in any()/all() by avoiding PyIter_Next() --
using a trick found in ifilter().
Feel free to backport to 2.5.
........
r59591 | andrew.kuchling | 2007-12-22 18:27:02 +0100 (Sat, 22 Dec 2007) | 1 line
Add item
........
Diffstat (limited to 'Lib/decimal.py')
-rw-r--r-- | Lib/decimal.py | 53 |
1 files changed, 19 insertions, 34 deletions
diff --git a/Lib/decimal.py b/Lib/decimal.py index b25f6e6..54e8cb4 100644 --- a/Lib/decimal.py +++ b/Lib/decimal.py @@ -184,7 +184,6 @@ class Clamped(DecimalException): number of zero digits are appended to the coefficient ("fold-down"). """ - class InvalidOperation(DecimalException): """An invalid operation was performed. @@ -210,14 +209,10 @@ class InvalidOperation(DecimalException): """ def handle(self, context, *args): if args: - if args[0] == 1: # sNaN, must drop 's' but keep diagnostics - ans = _dec_from_triple(args[1]._sign, args[1]._int, 'n', True) - return ans._fix_nan(context) - elif args[0] == 2: - return _dec_from_triple(args[1], args[2], 'n', True) + ans = _dec_from_triple(args[0]._sign, args[0]._int, 'n', True) + return ans._fix_nan(context) return NaN - class ConversionSyntax(InvalidOperation): """Trying to convert badly formed string. @@ -277,7 +272,6 @@ class Inexact(DecimalException): The inexact signal may be tested (or trapped) to determine if a given operation (or sequence of operations) was inexact. """ - pass class InvalidContext(InvalidOperation): """Invalid context. Unknown rounding, for example. @@ -304,7 +298,6 @@ class Rounded(DecimalException): The rounded signal may be tested (or trapped) to determine if a given operation (or sequence of operations) caused a loss of precision. """ - pass class Subnormal(DecimalException): """Exponent < Emin before rounding. @@ -316,7 +309,6 @@ class Subnormal(DecimalException): The subnormal signal may be tested (or trapped) to determine if a given or operation (or sequence of operations) yielded a subnormal result. """ - pass class Overflow(Inexact, Rounded): """Numerical overflow. @@ -338,7 +330,7 @@ class Overflow(Inexact, Rounded): the result is the same as for round-down if the sign of the intermediate result is 0, or is [1,inf] otherwise. In all cases, Inexact and Rounded will also be raised. - """ + """ def handle(self, context, sign, *args): if context.rounding in (ROUND_HALF_UP, ROUND_HALF_EVEN, @@ -662,7 +654,7 @@ class Decimal(_numbers.Real, _numbers.Inexact): """Returns whether the number is not actually one. 0 if a number - 1 if NaN (it could be a normal quiet NaN or a phantom one) + 1 if NaN 2 if sNaN """ if self._is_special: @@ -708,10 +700,10 @@ class Decimal(_numbers.Real, _numbers.Inexact): if self_is_nan == 2: return context._raise_error(InvalidOperation, 'sNaN', - 1, self) + self) if other_is_nan == 2: return context._raise_error(InvalidOperation, 'sNaN', - 1, other) + other) if self_is_nan: return self._fix_nan(context) @@ -922,7 +914,7 @@ class Decimal(_numbers.Real, _numbers.Inexact): if not self: # -Decimal('0') is Decimal('0'), not Decimal('-0') - ans = self.copy_sign(Dec_0) + ans = self.copy_abs() else: ans = self.copy_negate() @@ -942,7 +934,7 @@ class Decimal(_numbers.Real, _numbers.Inexact): if not self: # + (-0) = 0 - ans = self.copy_sign(Dec_0) + ans = self.copy_abs() else: ans = Decimal(self) @@ -1465,9 +1457,6 @@ class Decimal(_numbers.Real, _numbers.Inexact): context - context used. """ - if context is None: - context = getcontext() - if self._is_special: if self._isnan(): # decapitate payload if necessary @@ -1631,11 +1620,9 @@ class Decimal(_numbers.Real, _numbers.Inexact): if context is None: context = getcontext() if self._exp == 'N': - return context._raise_error(InvalidOperation, 'sNaN', - 1, self) + return context._raise_error(InvalidOperation, 'sNaN', self) if other._exp == 'N': - return context._raise_error(InvalidOperation, 'sNaN', - 1, other) + return context._raise_error(InvalidOperation, 'sNaN', other) if self._exp == 'n': product = self elif other._exp == 'n': @@ -1678,13 +1665,13 @@ class Decimal(_numbers.Real, _numbers.Inexact): if self_is_nan or other_is_nan or modulo_is_nan: if self_is_nan == 2: return context._raise_error(InvalidOperation, 'sNaN', - 1, self) + self) if other_is_nan == 2: return context._raise_error(InvalidOperation, 'sNaN', - 1, other) + other) if modulo_is_nan == 2: return context._raise_error(InvalidOperation, 'sNaN', - 1, modulo) + modulo) if self_is_nan: return self._fix_nan(context) if other_is_nan: @@ -2555,16 +2542,16 @@ class Decimal(_numbers.Real, _numbers.Inexact): other_is_nan = other._isnan() if self_is_nan == 2: return context._raise_error(InvalidOperation, 'sNaN', - 1, self) + self) if other_is_nan == 2: return context._raise_error(InvalidOperation, 'sNaN', - 1, other) + other) if self_is_nan: return context._raise_error(InvalidOperation, 'NaN in compare_signal', - 1, self) + self) if other_is_nan: return context._raise_error(InvalidOperation, 'NaN in compare_signal', - 1, other) + other) return self.compare(other, context=context) def compare_total(self, other): @@ -3208,8 +3195,8 @@ class Decimal(_numbers.Real, _numbers.Inexact): """Returns an indication of the class of self. The class is one of the following strings: - -sNaN - -NaN + sNaN + NaN -Infinity -Normal -Subnormal @@ -5173,8 +5160,6 @@ NaN = Decimal('NaN') Dec_0 = Decimal(0) Dec_p1 = Decimal(1) Dec_n1 = Decimal(-1) -Dec_p2 = Decimal(2) -Dec_n2 = Decimal(-2) # Infsign[sign] is infinity w/ that sign Infsign = (Inf, negInf) |