Skip to content

Commit e1ebddb

Browse files
author
raymond.hettinger
committedJan 3, 2009
Reapply r68191.
git-svn-id: http://svn.python.org/projects/python/trunk@68209 6015fed2-1504-0410-9fe1-9d1591cc4771
1 parent e94392e commit e1ebddb

File tree

1 file changed

+56
-56
lines changed

1 file changed

+56
-56
lines changed
 

‎Lib/decimal.py

+56-56
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,7 @@ class DivisionByZero(DecimalException, ZeroDivisionError):
243243
"""
244244

245245
def handle(self, context, sign, *args):
246-
return _Infsign[sign]
246+
return _SignedInfinity[sign]
247247

248248
class DivisionImpossible(InvalidOperation):
249249
"""Cannot perform the division adequately.
@@ -341,15 +341,15 @@ class Overflow(Inexact, Rounded):
341341
def handle(self, context, sign, *args):
342342
if context.rounding in (ROUND_HALF_UP, ROUND_HALF_EVEN,
343343
ROUND_HALF_DOWN, ROUND_UP):
344-
return _Infsign[sign]
344+
return _SignedInfinity[sign]
345345
if sign == 0:
346346
if context.rounding == ROUND_CEILING:
347-
return _Infsign[sign]
347+
return _SignedInfinity[sign]
348348
return _dec_from_triple(sign, '9'*context.prec,
349349
context.Emax-context.prec+1)
350350
if sign == 1:
351351
if context.rounding == ROUND_FLOOR:
352-
return _Infsign[sign]
352+
return _SignedInfinity[sign]
353353
return _dec_from_triple(sign, '9'*context.prec,
354354
context.Emax-context.prec+1)
355355

@@ -1204,12 +1204,12 @@ def __mul__(self, other, context=None):
12041204
if self._isinfinity():
12051205
if not other:
12061206
return context._raise_error(InvalidOperation, '(+-)INF * 0')
1207-
return _Infsign[resultsign]
1207+
return _SignedInfinity[resultsign]
12081208

12091209
if other._isinfinity():
12101210
if not self:
12111211
return context._raise_error(InvalidOperation, '0 * (+-)INF')
1212-
return _Infsign[resultsign]
1212+
return _SignedInfinity[resultsign]
12131213

12141214
resultexp = self._exp + other._exp
12151215

@@ -1259,7 +1259,7 @@ def __truediv__(self, other, context=None):
12591259
return context._raise_error(InvalidOperation, '(+-)INF/(+-)INF')
12601260

12611261
if self._isinfinity():
1262-
return _Infsign[sign]
1262+
return _SignedInfinity[sign]
12631263

12641264
if other._isinfinity():
12651265
context._raise_error(Clamped, 'Division by infinity')
@@ -1362,7 +1362,7 @@ def __divmod__(self, other, context=None):
13621362
ans = context._raise_error(InvalidOperation, 'divmod(INF, INF)')
13631363
return ans, ans
13641364
else:
1365-
return (_Infsign[sign],
1365+
return (_SignedInfinity[sign],
13661366
context._raise_error(InvalidOperation, 'INF % x'))
13671367

13681368
if not other:
@@ -1510,7 +1510,7 @@ def __floordiv__(self, other, context=None):
15101510
if other._isinfinity():
15111511
return context._raise_error(InvalidOperation, 'INF // INF')
15121512
else:
1513-
return _Infsign[self._sign ^ other._sign]
1513+
return _SignedInfinity[self._sign ^ other._sign]
15141514

15151515
if not other:
15161516
if self:
@@ -1765,12 +1765,12 @@ def fma(self, other, third, context=None):
17651765
if not other:
17661766
return context._raise_error(InvalidOperation,
17671767
'INF * 0 in fma')
1768-
product = _Infsign[self._sign ^ other._sign]
1768+
product = _SignedInfinity[self._sign ^ other._sign]
17691769
elif other._exp == 'F':
17701770
if not self:
17711771
return context._raise_error(InvalidOperation,
17721772
'0 * INF in fma')
1773-
product = _Infsign[self._sign ^ other._sign]
1773+
product = _SignedInfinity[self._sign ^ other._sign]
17741774
else:
17751775
product = _dec_from_triple(self._sign ^ other._sign,
17761776
str(int(self._int) * int(other._int)),
@@ -2120,7 +2120,7 @@ def __pow__(self, other, modulo=None, context=None):
21202120
if not self:
21212121
return context._raise_error(InvalidOperation, '0 ** 0')
21222122
else:
2123-
return _Dec_p1
2123+
return _One
21242124

21252125
# result has sign 1 iff self._sign is 1 and other is an odd integer
21262126
result_sign = 0
@@ -2142,19 +2142,19 @@ def __pow__(self, other, modulo=None, context=None):
21422142
if other._sign == 0:
21432143
return _dec_from_triple(result_sign, '0', 0)
21442144
else:
2145-
return _Infsign[result_sign]
2145+
return _SignedInfinity[result_sign]
21462146

21472147
# Inf**(+ve or Inf) = Inf; Inf**(-ve or -Inf) = 0
21482148
if self._isinfinity():
21492149
if other._sign == 0:
2150-
return _Infsign[result_sign]
2150+
return _SignedInfinity[result_sign]
21512151
else:
21522152
return _dec_from_triple(result_sign, '0', 0)
21532153

21542154
# 1**other = 1, but the choice of exponent and the flags
21552155
# depend on the exponent of self, and on whether other is a
21562156
# positive integer, a negative integer, or neither
2157-
if self == _Dec_p1:
2157+
if self == _One:
21582158
if other._isinteger():
21592159
# exp = max(self._exp*max(int(other), 0),
21602160
# 1-context.prec) but evaluating int(other) directly
@@ -2187,7 +2187,7 @@ def __pow__(self, other, modulo=None, context=None):
21872187
if (other._sign == 0) == (self_adj < 0):
21882188
return _dec_from_triple(result_sign, '0', 0)
21892189
else:
2190-
return _Infsign[result_sign]
2190+
return _SignedInfinity[result_sign]
21912191

21922192
# from here on, the result always goes through the call
21932193
# to _fix at the end of this function.
@@ -2707,9 +2707,9 @@ def compare_total(self, other):
27072707
"""
27082708
# if one is negative and the other is positive, it's easy
27092709
if self._sign and not other._sign:
2710-
return _Dec_n1
2710+
return _NegativeOne
27112711
if not self._sign and other._sign:
2712-
return _Dec_p1
2712+
return _One
27132713
sign = self._sign
27142714

27152715
# let's handle both NaN types
@@ -2719,51 +2719,51 @@ def compare_total(self, other):
27192719
if self_nan == other_nan:
27202720
if self._int < other._int:
27212721
if sign:
2722-
return _Dec_p1
2722+
return _One
27232723
else:
2724-
return _Dec_n1
2724+
return _NegativeOne
27252725
if self._int > other._int:
27262726
if sign:
2727-
return _Dec_n1
2727+
return _NegativeOne
27282728
else:
2729-
return _Dec_p1
2730-
return _Dec_0
2729+
return _One
2730+
return _Zero
27312731

27322732
if sign:
27332733
if self_nan == 1:
2734-
return _Dec_n1
2734+
return _NegativeOne
27352735
if other_nan == 1:
2736-
return _Dec_p1
2736+
return _One
27372737
if self_nan == 2:
2738-
return _Dec_n1
2738+
return _NegativeOne
27392739
if other_nan == 2:
2740-
return _Dec_p1
2740+
return _One
27412741
else:
27422742
if self_nan == 1:
2743-
return _Dec_p1
2743+
return _One
27442744
if other_nan == 1:
2745-
return _Dec_n1
2745+
return _NegativeOne
27462746
if self_nan == 2:
2747-
return _Dec_p1
2747+
return _One
27482748
if other_nan == 2:
2749-
return _Dec_n1
2749+
return _NegativeOne
27502750

27512751
if self < other:
2752-
return _Dec_n1
2752+
return _NegativeOne
27532753
if self > other:
2754-
return _Dec_p1
2754+
return _One
27552755

27562756
if self._exp < other._exp:
27572757
if sign:
2758-
return _Dec_p1
2758+
return _One
27592759
else:
2760-
return _Dec_n1
2760+
return _NegativeOne
27612761
if self._exp > other._exp:
27622762
if sign:
2763-
return _Dec_n1
2763+
return _NegativeOne
27642764
else:
2765-
return _Dec_p1
2766-
return _Dec_0
2765+
return _One
2766+
return _Zero
27672767

27682768

27692769
def compare_total_mag(self, other):
@@ -2804,11 +2804,11 @@ def exp(self, context=None):
28042804

28052805
# exp(-Infinity) = 0
28062806
if self._isinfinity() == -1:
2807-
return _Dec_0
2807+
return _Zero
28082808

28092809
# exp(0) = 1
28102810
if not self:
2811-
return _Dec_p1
2811+
return _One
28122812

28132813
# exp(Infinity) = Infinity
28142814
if self._isinfinity() == 1:
@@ -2960,15 +2960,15 @@ def ln(self, context=None):
29602960

29612961
# ln(0.0) == -Infinity
29622962
if not self:
2963-
return _negInf
2963+
return _NegativeInfinity
29642964

29652965
# ln(Infinity) = Infinity
29662966
if self._isinfinity() == 1:
2967-
return _Inf
2967+
return _Infinity
29682968

29692969
# ln(1.0) == 0.0
2970-
if self == _Dec_p1:
2971-
return _Dec_0
2970+
if self == _One:
2971+
return _Zero
29722972

29732973
# ln(negative) raises InvalidOperation
29742974
if self._sign == 1:
@@ -3040,11 +3040,11 @@ def log10(self, context=None):
30403040

30413041
# log10(0.0) == -Infinity
30423042
if not self:
3043-
return _negInf
3043+
return _NegativeInfinity
30443044

30453045
# log10(Infinity) = Infinity
30463046
if self._isinfinity() == 1:
3047-
return _Inf
3047+
return _Infinity
30483048

30493049
# log10(negative or -Infinity) raises InvalidOperation
30503050
if self._sign == 1:
@@ -3096,7 +3096,7 @@ def logb(self, context=None):
30963096

30973097
# logb(+/-Inf) = +Inf
30983098
if self._isinfinity():
3099-
return _Inf
3099+
return _Infinity
31003100

31013101
# logb(0) = -Inf, DivisionByZero
31023102
if not self:
@@ -3253,7 +3253,7 @@ def next_minus(self, context=None):
32533253
return ans
32543254

32553255
if self._isinfinity() == -1:
3256-
return _negInf
3256+
return _NegativeInfinity
32573257
if self._isinfinity() == 1:
32583258
return _dec_from_triple(0, '9'*context.prec, context.Etop())
32593259

@@ -3276,7 +3276,7 @@ def next_plus(self, context=None):
32763276
return ans
32773277

32783278
if self._isinfinity() == 1:
3279-
return _Inf
3279+
return _Infinity
32803280
if self._isinfinity() == -1:
32813281
return _dec_from_triple(1, '9'*context.prec, context.Etop())
32823282

@@ -5540,15 +5540,15 @@ def _format_align(body, spec_dict):
55405540
##### Useful Constants (internal use only) ################################
55415541

55425542
# Reusable defaults
5543-
_Inf = Decimal('Inf')
5544-
_negInf = Decimal('-Inf')
5543+
_Infinity = Decimal('Inf')
5544+
_NegativeInfinity = Decimal('-Inf')
55455545
_NaN = Decimal('NaN')
5546-
_Dec_0 = Decimal(0)
5547-
_Dec_p1 = Decimal(1)
5548-
_Dec_n1 = Decimal(-1)
5546+
_Zero = Decimal(0)
5547+
_One = Decimal(1)
5548+
_NegativeOne = Decimal(-1)
55495549

5550-
# _Infsign[sign] is infinity w/ that sign
5551-
_Infsign = (_Inf, _negInf)
5550+
# _SignedInfinity[sign] is infinity w/ that sign
5551+
_SignedInfinity = (_Infinity, _NegativeInfinity)
55525552

55535553

55545554

0 commit comments

Comments
 (0)
Please sign in to comment.