[Python-Dev] [Python-checkins] r68182 - in python/trunk: Lib/decimal.py Misc/NEWS (original) (raw)
Jim Jewett jimjjewett at gmail.com
Mon Jan 5 16:12:34 CET 2009
- Previous message: [Python-Dev] issue 3582
- Next message: [Python-Dev] [Python-checkins] r68182 - in python/trunk: Lib/decimal.py Misc/NEWS
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Our of curiousity, why are these constants for internal use only?
Is there concern that people might start using "is", or is it just to keep the (beyond the spec) API small, or ...?
-jJ
On Fri, Jan 2, 2009 at 6:07 PM, mark. dickinson <python-checkins at python.org> wrote:
Author: mark.dickinson Date: Sat Jan 3 00:07:08 2009 New Revision: 68182
Log: Issue #4812: add missing underscore prefix to some internal-use-only constants in the decimal module. (Dec0 becomes Dec0, etc.)
Modified: python/trunk/Lib/decimal.py python/trunk/Misc/NEWS Modified: python/trunk/Lib/decimal.py ============================================================================== --- python/trunk/Lib/decimal.py (original) +++ python/trunk/Lib/decimal.py Sat Jan 3 00:07:08 2009 @@ -216,7 +216,7 @@ if args: ans = decfromtriple(args[0].sign, args[0].int, 'n', True) return ans.fixnan(context) - return NaN + return NaN class ConversionSyntax(InvalidOperation): """Trying to convert badly formed string. @@ -226,7 +226,7 @@ syntax. The result is [0,qNaN]. """ def handle(self, context, *args): - return NaN + return NaN class DivisionByZero(DecimalException, ZeroDivisionError): """Division by 0. @@ -242,7 +242,7 @@ """ def handle(self, context, sign, *args): - return Infsign[sign] + return Infsign[sign] class DivisionImpossible(InvalidOperation): """Cannot perform the division adequately. @@ -253,7 +253,7 @@ """ def handle(self, context, *args): - return NaN + return NaN class DivisionUndefined(InvalidOperation, ZeroDivisionError): """Undefined result of division. @@ -264,7 +264,7 @@ """ def handle(self, context, *args): - return NaN + return NaN class Inexact(DecimalException): """Had to round, losing information. @@ -290,7 +290,7 @@ """ def handle(self, context, *args): - return NaN + return NaN class Rounded(DecimalException): """Number got rounded (not necessarily changed during rounding). @@ -340,15 +340,15 @@ def handle(self, context, sign, *args): if context.rounding in (ROUNDHALFUP, ROUNDHALFEVEN, ROUNDHALFDOWN, ROUNDUP): - return Infsign[sign] + return Infsign[sign] if sign == 0: if context.rounding == ROUNDCEILING: - return Infsign[sign] + return Infsign[sign] return decfromtriple(sign, '9'*context.prec, context.Emax-context.prec+1) if sign == 1: if context.rounding == ROUNDFLOOR: - return Infsign[sign] + return Infsign[sign] return decfromtriple(sign, '9'*context.prec, context.Emax-context.prec+1) @@ -1171,12 +1171,12 @@ if self.isinfinity(): if not other: return context.raiseerror(InvalidOperation, '(+-)INF * 0') - return Infsign[resultsign] + return Infsign[resultsign] if other.isinfinity(): if not self: return context.raiseerror(InvalidOperation, '0 * (+-)INF') - return Infsign[resultsign] + return Infsign[resultsign] resultexp = self.exp + other.exp @@ -1226,7 +1226,7 @@ return context.raiseerror(InvalidOperation, '(+-)INF/(+-)INF') if self.isinfinity(): - return Infsign[sign] + return Infsign[sign] if other.isinfinity(): context.raiseerror(Clamped, 'Division by infinity') @@ -1329,7 +1329,7 @@ ans = context.raiseerror(InvalidOperation, 'divmod(INF, INF)') return ans, ans else: - return (Infsign[sign], + return (Infsign[sign], context.raiseerror(InvalidOperation, 'INF % x')) if not other: @@ -1477,7 +1477,7 @@ if other.isinfinity(): return context.raiseerror(InvalidOperation, 'INF // INF') else: - return Infsign[self.sign ^ other.sign] + return Infsign[self.sign ^ other.sign] if not other: if self: @@ -1732,12 +1732,12 @@ if not other: return context.raiseerror(InvalidOperation, 'INF * 0 in fma') - product = Infsign[self.sign ^ other.sign] + product = Infsign[self.sign ^ other.sign] elif other.exp == 'F': if not self: return context.raiseerror(InvalidOperation, '0 * INF in fma') - product = Infsign[self.sign ^ other.sign] + product = Infsign[self.sign ^ other.sign] else: product = decfromtriple(self.sign ^ other.sign, str(int(self.int) * int(other.int)), @@ -2087,7 +2087,7 @@ if not self: return context.raiseerror(InvalidOperation, '0 ** 0') else: - return Decp1 + return Decp1 # result has sign 1 iff self.sign is 1 and other is an odd integer resultsign = 0 @@ -2109,19 +2109,19 @@ if other.sign == 0: return decfromtriple(resultsign, '0', 0) else: - return Infsign[resultsign] + return Infsign[resultsign] # Inf**(+ve or Inf) = Inf; Inf**(-ve or -Inf) = 0 if self.isinfinity(): if other.sign == 0: - return Infsign[resultsign] + return Infsign[resultsign] else: return decfromtriple(resultsign, '0', 0) # 1**other = 1, but the choice of exponent and the flags # depend on the exponent of self, and on whether other is a # positive integer, a negative integer, or neither - if self == Decp1: + if self == Decp1: if other.isinteger(): # exp = max(self.exp*max(int(other), 0), # 1-context.prec) but evaluating int(other) directly @@ -2154,7 +2154,7 @@ if (other.sign == 0) == (selfadj < 0):_ _return decfromtriple(resultsign, '0', 0)_ _else:_ _- return Infsign[resultsign]_ _+ return Infsign[resultsign]_ _# from here on, the result always goes through the call_ _# to fix at the end of this function._ _@@ -2674,9 +2674,9 @@_ _"""_ _# if one is negative and the other is positive, it's easy_ _if self.sign and not other.sign:_ _- return Decn1_ _+ return Decn1_ _if not self.sign and other.sign:_ _- return Decp1_ _+ return Decp1_ _sign = self.sign_ _# let's handle both NaN types_ _@@ -2686,51 +2686,51 @@_ _if selfnan == othernan:_ _if self.int < other.int:_ _if sign:_ _- return Decp1_ _+ return Decp1_ _else:_ _- return Decn1_ _+ return Decn1_ _if self.int > other.int: if sign: - return Decn1 + return Decn1 else: - return Decp1 - return Dec0 + return Decp1 + return Dec0 if sign: if selfnan == 1: - return Decn1 + return Decn1 if othernan == 1: - return Decp1 + return Decp1 if selfnan == 2: - return Decn1 + return Decn1 if othernan == 2: - return Decp1 + return Decp1 else: if selfnan == 1: - return Decp1 + return Decp1 if othernan == 1: - return Decn1 + return Decn1 if selfnan == 2: - return Decp1 + return Decp1 if othernan == 2: - return Decn1 + return Decn1 if self < other:_ _- return Decn1_ _+ return Decn1_ _if self > other: - return Decp1 + return Decp1 if self.exp < other.exp:_ _if sign:_ _- return Decp1_ _+ return Decp1_ _else:_ _- return Decn1_ _+ return Decn1_ _if self.exp > other.exp: if sign: - return Decn1 + return Decn1 else: - return Decp1 - return Dec0 + return Decp1 + return Dec0 def comparetotalmag(self, other): @@ -2771,11 +2771,11 @@ # exp(-Infinity) = 0 if self.isinfinity() == -1: - return Dec0 + return Dec0 # exp(0) = 1 if not self: - return Decp1 + return Decp1 # exp(Infinity) = Infinity if self.isinfinity() == 1: @@ -2927,15 +2927,15 @@ # ln(0.0) == -Infinity if not self: - return negInf + return negInf # ln(Infinity) = Infinity if self.isinfinity() == 1: - return Inf + return Inf # ln(1.0) == 0.0 - if self == Decp1: - return Dec0 + if self == Decp1: + return Dec0 # ln(negative) raises InvalidOperation if self.sign == 1: @@ -3007,11 +3007,11 @@ # log10(0.0) == -Infinity if not self: - return negInf + return negInf # log10(Infinity) = Infinity if self.isinfinity() == 1: - return Inf + return Inf # log10(negative or -Infinity) raises InvalidOperation if self.sign == 1: @@ -3063,7 +3063,7 @@ # logb(+/-Inf) = +Inf if self.isinfinity(): - return Inf + return Inf # logb(0) = -Inf, DivisionByZero if not self: @@ -3220,7 +3220,7 @@ return ans if self.isinfinity() == -1: - return negInf + return negInf if self.isinfinity() == 1: return decfromtriple(0, '9'*context.prec, context.Etop()) @@ -3243,7 +3243,7 @@ return ans if self.isinfinity() == 1: - return Inf + return Inf if self.isinfinity() == -1: return decfromtriple(1, '9'*context.prec, context.Etop()) @@ -5490,15 +5490,15 @@ ##### Useful Constants (internal use only) ################################ # Reusable defaults -Inf = Decimal('Inf') -negInf = Decimal('-Inf') -NaN = Decimal('NaN') -Dec0 = Decimal(0) -Decp1 = Decimal(1) -Decn1 = Decimal(-1) +Inf = Decimal('Inf') +negInf = Decimal('-Inf') +NaN = Decimal('NaN') +Dec0 = Decimal(0) +Decp1 = Decimal(1) +Decn1 = Decimal(-1) -# Infsign[sign] is infinity w/ that sign -Infsign = (Inf, negInf) +# Infsign[sign] is infinity w/ that sign +Infsign = (Inf, negInf)
Modified: python/trunk/Misc/NEWS ============================================================================== --- python/trunk/Misc/NEWS (original) +++ python/trunk/Misc/NEWS Sat Jan 3 00:07:08 2009 @@ -108,6 +108,9 @@ Library ------- +- Issue #4812: add missing underscore prefix to some internal-use-only + constants in the decimal module. (Dec0 becomes Dec0, etc.) + - Issue #4795: inspect.isgeneratorfunction() returns False instead of None when the function is not a generator.
Python-checkins mailing list Python-checkins at python.org http://mail.python.org/mailman/listinfo/python-checkins
- Previous message: [Python-Dev] issue 3582
- Next message: [Python-Dev] [Python-checkins] r68182 - in python/trunk: Lib/decimal.py Misc/NEWS
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]