mirror of
https://github.com/python/cpython.git
synced 2025-08-28 20:56:54 +00:00
Merged revisions 68182 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk ........ r68182 | mark.dickinson | 2009-01-02 23:07:08 +0000 (Fri, 02 Jan 2009) | 4 lines Issue #4812: add missing underscore prefix to some internal-use-only constants in the decimal module. (Dec_0 becomes _Dec_0, etc.) ........
This commit is contained in:
parent
ad9d96bc1a
commit
f923641b41
2 changed files with 65 additions and 62 deletions
124
Lib/decimal.py
124
Lib/decimal.py
|
@ -217,7 +217,7 @@ class InvalidOperation(DecimalException):
|
||||||
if args:
|
if args:
|
||||||
ans = _dec_from_triple(args[0]._sign, args[0]._int, 'n', True)
|
ans = _dec_from_triple(args[0]._sign, args[0]._int, 'n', True)
|
||||||
return ans._fix_nan(context)
|
return ans._fix_nan(context)
|
||||||
return NaN
|
return _NaN
|
||||||
|
|
||||||
class ConversionSyntax(InvalidOperation):
|
class ConversionSyntax(InvalidOperation):
|
||||||
"""Trying to convert badly formed string.
|
"""Trying to convert badly formed string.
|
||||||
|
@ -227,7 +227,7 @@ class ConversionSyntax(InvalidOperation):
|
||||||
syntax. The result is [0,qNaN].
|
syntax. The result is [0,qNaN].
|
||||||
"""
|
"""
|
||||||
def handle(self, context, *args):
|
def handle(self, context, *args):
|
||||||
return NaN
|
return _NaN
|
||||||
|
|
||||||
class DivisionByZero(DecimalException, ZeroDivisionError):
|
class DivisionByZero(DecimalException, ZeroDivisionError):
|
||||||
"""Division by 0.
|
"""Division by 0.
|
||||||
|
@ -243,7 +243,7 @@ class DivisionByZero(DecimalException, ZeroDivisionError):
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def handle(self, context, sign, *args):
|
def handle(self, context, sign, *args):
|
||||||
return Infsign[sign]
|
return _Infsign[sign]
|
||||||
|
|
||||||
class DivisionImpossible(InvalidOperation):
|
class DivisionImpossible(InvalidOperation):
|
||||||
"""Cannot perform the division adequately.
|
"""Cannot perform the division adequately.
|
||||||
|
@ -254,7 +254,7 @@ class DivisionImpossible(InvalidOperation):
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def handle(self, context, *args):
|
def handle(self, context, *args):
|
||||||
return NaN
|
return _NaN
|
||||||
|
|
||||||
class DivisionUndefined(InvalidOperation, ZeroDivisionError):
|
class DivisionUndefined(InvalidOperation, ZeroDivisionError):
|
||||||
"""Undefined result of division.
|
"""Undefined result of division.
|
||||||
|
@ -265,7 +265,7 @@ class DivisionUndefined(InvalidOperation, ZeroDivisionError):
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def handle(self, context, *args):
|
def handle(self, context, *args):
|
||||||
return NaN
|
return _NaN
|
||||||
|
|
||||||
class Inexact(DecimalException):
|
class Inexact(DecimalException):
|
||||||
"""Had to round, losing information.
|
"""Had to round, losing information.
|
||||||
|
@ -291,7 +291,7 @@ class InvalidContext(InvalidOperation):
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def handle(self, context, *args):
|
def handle(self, context, *args):
|
||||||
return NaN
|
return _NaN
|
||||||
|
|
||||||
class Rounded(DecimalException):
|
class Rounded(DecimalException):
|
||||||
"""Number got rounded (not necessarily changed during rounding).
|
"""Number got rounded (not necessarily changed during rounding).
|
||||||
|
@ -341,15 +341,15 @@ class Overflow(Inexact, Rounded):
|
||||||
def handle(self, context, sign, *args):
|
def handle(self, context, sign, *args):
|
||||||
if context.rounding in (ROUND_HALF_UP, ROUND_HALF_EVEN,
|
if context.rounding in (ROUND_HALF_UP, ROUND_HALF_EVEN,
|
||||||
ROUND_HALF_DOWN, ROUND_UP):
|
ROUND_HALF_DOWN, ROUND_UP):
|
||||||
return Infsign[sign]
|
return _Infsign[sign]
|
||||||
if sign == 0:
|
if sign == 0:
|
||||||
if context.rounding == ROUND_CEILING:
|
if context.rounding == ROUND_CEILING:
|
||||||
return Infsign[sign]
|
return _Infsign[sign]
|
||||||
return _dec_from_triple(sign, '9'*context.prec,
|
return _dec_from_triple(sign, '9'*context.prec,
|
||||||
context.Emax-context.prec+1)
|
context.Emax-context.prec+1)
|
||||||
if sign == 1:
|
if sign == 1:
|
||||||
if context.rounding == ROUND_FLOOR:
|
if context.rounding == ROUND_FLOOR:
|
||||||
return Infsign[sign]
|
return _Infsign[sign]
|
||||||
return _dec_from_triple(sign, '9'*context.prec,
|
return _dec_from_triple(sign, '9'*context.prec,
|
||||||
context.Emax-context.prec+1)
|
context.Emax-context.prec+1)
|
||||||
|
|
||||||
|
@ -1173,12 +1173,12 @@ class Decimal(_numbers.Real):
|
||||||
if self._isinfinity():
|
if self._isinfinity():
|
||||||
if not other:
|
if not other:
|
||||||
return context._raise_error(InvalidOperation, '(+-)INF * 0')
|
return context._raise_error(InvalidOperation, '(+-)INF * 0')
|
||||||
return Infsign[resultsign]
|
return _Infsign[resultsign]
|
||||||
|
|
||||||
if other._isinfinity():
|
if other._isinfinity():
|
||||||
if not self:
|
if not self:
|
||||||
return context._raise_error(InvalidOperation, '0 * (+-)INF')
|
return context._raise_error(InvalidOperation, '0 * (+-)INF')
|
||||||
return Infsign[resultsign]
|
return _Infsign[resultsign]
|
||||||
|
|
||||||
resultexp = self._exp + other._exp
|
resultexp = self._exp + other._exp
|
||||||
|
|
||||||
|
@ -1228,7 +1228,7 @@ class Decimal(_numbers.Real):
|
||||||
return context._raise_error(InvalidOperation, '(+-)INF/(+-)INF')
|
return context._raise_error(InvalidOperation, '(+-)INF/(+-)INF')
|
||||||
|
|
||||||
if self._isinfinity():
|
if self._isinfinity():
|
||||||
return Infsign[sign]
|
return _Infsign[sign]
|
||||||
|
|
||||||
if other._isinfinity():
|
if other._isinfinity():
|
||||||
context._raise_error(Clamped, 'Division by infinity')
|
context._raise_error(Clamped, 'Division by infinity')
|
||||||
|
@ -1328,7 +1328,7 @@ class Decimal(_numbers.Real):
|
||||||
ans = context._raise_error(InvalidOperation, 'divmod(INF, INF)')
|
ans = context._raise_error(InvalidOperation, 'divmod(INF, INF)')
|
||||||
return ans, ans
|
return ans, ans
|
||||||
else:
|
else:
|
||||||
return (Infsign[sign],
|
return (_Infsign[sign],
|
||||||
context._raise_error(InvalidOperation, 'INF % x'))
|
context._raise_error(InvalidOperation, 'INF % x'))
|
||||||
|
|
||||||
if not other:
|
if not other:
|
||||||
|
@ -1476,7 +1476,7 @@ class Decimal(_numbers.Real):
|
||||||
if other._isinfinity():
|
if other._isinfinity():
|
||||||
return context._raise_error(InvalidOperation, 'INF // INF')
|
return context._raise_error(InvalidOperation, 'INF // INF')
|
||||||
else:
|
else:
|
||||||
return Infsign[self._sign ^ other._sign]
|
return _Infsign[self._sign ^ other._sign]
|
||||||
|
|
||||||
if not other:
|
if not other:
|
||||||
if self:
|
if self:
|
||||||
|
@ -1820,12 +1820,12 @@ class Decimal(_numbers.Real):
|
||||||
if not other:
|
if not other:
|
||||||
return context._raise_error(InvalidOperation,
|
return context._raise_error(InvalidOperation,
|
||||||
'INF * 0 in fma')
|
'INF * 0 in fma')
|
||||||
product = Infsign[self._sign ^ other._sign]
|
product = _Infsign[self._sign ^ other._sign]
|
||||||
elif other._exp == 'F':
|
elif other._exp == 'F':
|
||||||
if not self:
|
if not self:
|
||||||
return context._raise_error(InvalidOperation,
|
return context._raise_error(InvalidOperation,
|
||||||
'0 * INF in fma')
|
'0 * INF in fma')
|
||||||
product = Infsign[self._sign ^ other._sign]
|
product = _Infsign[self._sign ^ other._sign]
|
||||||
else:
|
else:
|
||||||
product = _dec_from_triple(self._sign ^ other._sign,
|
product = _dec_from_triple(self._sign ^ other._sign,
|
||||||
str(int(self._int) * int(other._int)),
|
str(int(self._int) * int(other._int)),
|
||||||
|
@ -2175,7 +2175,7 @@ class Decimal(_numbers.Real):
|
||||||
if not self:
|
if not self:
|
||||||
return context._raise_error(InvalidOperation, '0 ** 0')
|
return context._raise_error(InvalidOperation, '0 ** 0')
|
||||||
else:
|
else:
|
||||||
return Dec_p1
|
return _Dec_p1
|
||||||
|
|
||||||
# result has sign 1 iff self._sign is 1 and other is an odd integer
|
# result has sign 1 iff self._sign is 1 and other is an odd integer
|
||||||
result_sign = 0
|
result_sign = 0
|
||||||
|
@ -2197,19 +2197,19 @@ class Decimal(_numbers.Real):
|
||||||
if other._sign == 0:
|
if other._sign == 0:
|
||||||
return _dec_from_triple(result_sign, '0', 0)
|
return _dec_from_triple(result_sign, '0', 0)
|
||||||
else:
|
else:
|
||||||
return Infsign[result_sign]
|
return _Infsign[result_sign]
|
||||||
|
|
||||||
# Inf**(+ve or Inf) = Inf; Inf**(-ve or -Inf) = 0
|
# Inf**(+ve or Inf) = Inf; Inf**(-ve or -Inf) = 0
|
||||||
if self._isinfinity():
|
if self._isinfinity():
|
||||||
if other._sign == 0:
|
if other._sign == 0:
|
||||||
return Infsign[result_sign]
|
return _Infsign[result_sign]
|
||||||
else:
|
else:
|
||||||
return _dec_from_triple(result_sign, '0', 0)
|
return _dec_from_triple(result_sign, '0', 0)
|
||||||
|
|
||||||
# 1**other = 1, but the choice of exponent and the flags
|
# 1**other = 1, but the choice of exponent and the flags
|
||||||
# depend on the exponent of self, and on whether other is a
|
# depend on the exponent of self, and on whether other is a
|
||||||
# positive integer, a negative integer, or neither
|
# positive integer, a negative integer, or neither
|
||||||
if self == Dec_p1:
|
if self == _Dec_p1:
|
||||||
if other._isinteger():
|
if other._isinteger():
|
||||||
# exp = max(self._exp*max(int(other), 0),
|
# exp = max(self._exp*max(int(other), 0),
|
||||||
# 1-context.prec) but evaluating int(other) directly
|
# 1-context.prec) but evaluating int(other) directly
|
||||||
|
@ -2242,7 +2242,7 @@ class Decimal(_numbers.Real):
|
||||||
if (other._sign == 0) == (self_adj < 0):
|
if (other._sign == 0) == (self_adj < 0):
|
||||||
return _dec_from_triple(result_sign, '0', 0)
|
return _dec_from_triple(result_sign, '0', 0)
|
||||||
else:
|
else:
|
||||||
return Infsign[result_sign]
|
return _Infsign[result_sign]
|
||||||
|
|
||||||
# from here on, the result always goes through the call
|
# from here on, the result always goes through the call
|
||||||
# to _fix at the end of this function.
|
# to _fix at the end of this function.
|
||||||
|
@ -2762,9 +2762,9 @@ class Decimal(_numbers.Real):
|
||||||
"""
|
"""
|
||||||
# if one is negative and the other is positive, it's easy
|
# if one is negative and the other is positive, it's easy
|
||||||
if self._sign and not other._sign:
|
if self._sign and not other._sign:
|
||||||
return Dec_n1
|
return _Dec_n1
|
||||||
if not self._sign and other._sign:
|
if not self._sign and other._sign:
|
||||||
return Dec_p1
|
return _Dec_p1
|
||||||
sign = self._sign
|
sign = self._sign
|
||||||
|
|
||||||
# let's handle both NaN types
|
# let's handle both NaN types
|
||||||
|
@ -2774,51 +2774,51 @@ class Decimal(_numbers.Real):
|
||||||
if self_nan == other_nan:
|
if self_nan == other_nan:
|
||||||
if self._int < other._int:
|
if self._int < other._int:
|
||||||
if sign:
|
if sign:
|
||||||
return Dec_p1
|
return _Dec_p1
|
||||||
else:
|
else:
|
||||||
return Dec_n1
|
return _Dec_n1
|
||||||
if self._int > other._int:
|
if self._int > other._int:
|
||||||
if sign:
|
if sign:
|
||||||
return Dec_n1
|
return _Dec_n1
|
||||||
else:
|
else:
|
||||||
return Dec_p1
|
return _Dec_p1
|
||||||
return Dec_0
|
return _Dec_0
|
||||||
|
|
||||||
if sign:
|
if sign:
|
||||||
if self_nan == 1:
|
if self_nan == 1:
|
||||||
return Dec_n1
|
return _Dec_n1
|
||||||
if other_nan == 1:
|
if other_nan == 1:
|
||||||
return Dec_p1
|
return _Dec_p1
|
||||||
if self_nan == 2:
|
if self_nan == 2:
|
||||||
return Dec_n1
|
return _Dec_n1
|
||||||
if other_nan == 2:
|
if other_nan == 2:
|
||||||
return Dec_p1
|
return _Dec_p1
|
||||||
else:
|
else:
|
||||||
if self_nan == 1:
|
if self_nan == 1:
|
||||||
return Dec_p1
|
return _Dec_p1
|
||||||
if other_nan == 1:
|
if other_nan == 1:
|
||||||
return Dec_n1
|
return _Dec_n1
|
||||||
if self_nan == 2:
|
if self_nan == 2:
|
||||||
return Dec_p1
|
return _Dec_p1
|
||||||
if other_nan == 2:
|
if other_nan == 2:
|
||||||
return Dec_n1
|
return _Dec_n1
|
||||||
|
|
||||||
if self < other:
|
if self < other:
|
||||||
return Dec_n1
|
return _Dec_n1
|
||||||
if self > other:
|
if self > other:
|
||||||
return Dec_p1
|
return _Dec_p1
|
||||||
|
|
||||||
if self._exp < other._exp:
|
if self._exp < other._exp:
|
||||||
if sign:
|
if sign:
|
||||||
return Dec_p1
|
return _Dec_p1
|
||||||
else:
|
else:
|
||||||
return Dec_n1
|
return _Dec_n1
|
||||||
if self._exp > other._exp:
|
if self._exp > other._exp:
|
||||||
if sign:
|
if sign:
|
||||||
return Dec_n1
|
return _Dec_n1
|
||||||
else:
|
else:
|
||||||
return Dec_p1
|
return _Dec_p1
|
||||||
return Dec_0
|
return _Dec_0
|
||||||
|
|
||||||
|
|
||||||
def compare_total_mag(self, other):
|
def compare_total_mag(self, other):
|
||||||
|
@ -2859,11 +2859,11 @@ class Decimal(_numbers.Real):
|
||||||
|
|
||||||
# exp(-Infinity) = 0
|
# exp(-Infinity) = 0
|
||||||
if self._isinfinity() == -1:
|
if self._isinfinity() == -1:
|
||||||
return Dec_0
|
return _Dec_0
|
||||||
|
|
||||||
# exp(0) = 1
|
# exp(0) = 1
|
||||||
if not self:
|
if not self:
|
||||||
return Dec_p1
|
return _Dec_p1
|
||||||
|
|
||||||
# exp(Infinity) = Infinity
|
# exp(Infinity) = Infinity
|
||||||
if self._isinfinity() == 1:
|
if self._isinfinity() == 1:
|
||||||
|
@ -3015,15 +3015,15 @@ class Decimal(_numbers.Real):
|
||||||
|
|
||||||
# ln(0.0) == -Infinity
|
# ln(0.0) == -Infinity
|
||||||
if not self:
|
if not self:
|
||||||
return negInf
|
return _negInf
|
||||||
|
|
||||||
# ln(Infinity) = Infinity
|
# ln(Infinity) = Infinity
|
||||||
if self._isinfinity() == 1:
|
if self._isinfinity() == 1:
|
||||||
return Inf
|
return _Inf
|
||||||
|
|
||||||
# ln(1.0) == 0.0
|
# ln(1.0) == 0.0
|
||||||
if self == Dec_p1:
|
if self == _Dec_p1:
|
||||||
return Dec_0
|
return _Dec_0
|
||||||
|
|
||||||
# ln(negative) raises InvalidOperation
|
# ln(negative) raises InvalidOperation
|
||||||
if self._sign == 1:
|
if self._sign == 1:
|
||||||
|
@ -3095,11 +3095,11 @@ class Decimal(_numbers.Real):
|
||||||
|
|
||||||
# log10(0.0) == -Infinity
|
# log10(0.0) == -Infinity
|
||||||
if not self:
|
if not self:
|
||||||
return negInf
|
return _negInf
|
||||||
|
|
||||||
# log10(Infinity) = Infinity
|
# log10(Infinity) = Infinity
|
||||||
if self._isinfinity() == 1:
|
if self._isinfinity() == 1:
|
||||||
return Inf
|
return _Inf
|
||||||
|
|
||||||
# log10(negative or -Infinity) raises InvalidOperation
|
# log10(negative or -Infinity) raises InvalidOperation
|
||||||
if self._sign == 1:
|
if self._sign == 1:
|
||||||
|
@ -3151,7 +3151,7 @@ class Decimal(_numbers.Real):
|
||||||
|
|
||||||
# logb(+/-Inf) = +Inf
|
# logb(+/-Inf) = +Inf
|
||||||
if self._isinfinity():
|
if self._isinfinity():
|
||||||
return Inf
|
return _Inf
|
||||||
|
|
||||||
# logb(0) = -Inf, DivisionByZero
|
# logb(0) = -Inf, DivisionByZero
|
||||||
if not self:
|
if not self:
|
||||||
|
@ -3308,7 +3308,7 @@ class Decimal(_numbers.Real):
|
||||||
return ans
|
return ans
|
||||||
|
|
||||||
if self._isinfinity() == -1:
|
if self._isinfinity() == -1:
|
||||||
return negInf
|
return _negInf
|
||||||
if self._isinfinity() == 1:
|
if self._isinfinity() == 1:
|
||||||
return _dec_from_triple(0, '9'*context.prec, context.Etop())
|
return _dec_from_triple(0, '9'*context.prec, context.Etop())
|
||||||
|
|
||||||
|
@ -3331,7 +3331,7 @@ class Decimal(_numbers.Real):
|
||||||
return ans
|
return ans
|
||||||
|
|
||||||
if self._isinfinity() == 1:
|
if self._isinfinity() == 1:
|
||||||
return Inf
|
return _Inf
|
||||||
if self._isinfinity() == -1:
|
if self._isinfinity() == -1:
|
||||||
return _dec_from_triple(1, '9'*context.prec, context.Etop())
|
return _dec_from_triple(1, '9'*context.prec, context.Etop())
|
||||||
|
|
||||||
|
@ -5572,15 +5572,15 @@ def _format_align(body, spec_dict):
|
||||||
##### Useful Constants (internal use only) ################################
|
##### Useful Constants (internal use only) ################################
|
||||||
|
|
||||||
# Reusable defaults
|
# Reusable defaults
|
||||||
Inf = Decimal('Inf')
|
_Inf = Decimal('Inf')
|
||||||
negInf = Decimal('-Inf')
|
_negInf = Decimal('-Inf')
|
||||||
NaN = Decimal('NaN')
|
_NaN = Decimal('NaN')
|
||||||
Dec_0 = Decimal(0)
|
_Dec_0 = Decimal(0)
|
||||||
Dec_p1 = Decimal(1)
|
_Dec_p1 = Decimal(1)
|
||||||
Dec_n1 = Decimal(-1)
|
_Dec_n1 = Decimal(-1)
|
||||||
|
|
||||||
# Infsign[sign] is infinity w/ that sign
|
# _Infsign[sign] is infinity w/ that sign
|
||||||
Infsign = (Inf, negInf)
|
_Infsign = (_Inf, _negInf)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -78,6 +78,9 @@ Core and Builtins
|
||||||
Library
|
Library
|
||||||
-------
|
-------
|
||||||
|
|
||||||
|
- Issue #4812: add missing underscore prefix to some internal-use-only
|
||||||
|
constants in the decimal module. (Dec_0 becomes _Dec_0, etc.)
|
||||||
|
|
||||||
- Issue #4702: Throwing a DistutilsPlatformError instead of IOError in case
|
- Issue #4702: Throwing a DistutilsPlatformError instead of IOError in case
|
||||||
no MSVC compiler is found under Windows. Original patch by Philip Jenvey.
|
no MSVC compiler is found under Windows. Original patch by Philip Jenvey.
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue