Skip to content
Projeler
Gruplar
Parçacıklar
Yardım
Yükleniyor...
Oturum aç / Kaydol
Gezinmeyi değiştir
C
cpython
Proje
Proje
Ayrıntılar
Etkinlik
Cycle Analytics
Depo (repository)
Depo (repository)
Dosyalar
Kayıtlar (commit)
Dallar (branch)
Etiketler
Katkıda bulunanlar
Grafik
Karşılaştır
Grafikler
Konular (issue)
0
Konular (issue)
0
Liste
Pano
Etiketler
Kilometre Taşları
Birleştirme (merge) Talepleri
0
Birleştirme (merge) Talepleri
0
CI / CD
CI / CD
İş akışları (pipeline)
İşler
Zamanlamalar
Grafikler
Paketler
Paketler
Wiki
Wiki
Parçacıklar
Parçacıklar
Üyeler
Üyeler
Collapse sidebar
Close sidebar
Etkinlik
Grafik
Grafikler
Yeni bir konu (issue) oluştur
İşler
Kayıtlar (commit)
Konu (issue) Panoları
Kenar çubuğunu aç
Batuhan Osman TASKAYA
cpython
Commits
b7e835b8
Kaydet (Commit)
b7e835b8
authored
Ock 03, 2009
tarafından
Raymond Hettinger
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Reapply r68191.
üst
f4d8597a
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
56 additions
and
56 deletions
+56
-56
decimal.py
Lib/decimal.py
+56
-56
No files found.
Lib/decimal.py
Dosyayı görüntüle @
b7e835b8
...
...
@@ -243,7 +243,7 @@ class DivisionByZero(DecimalException, ZeroDivisionError):
"""
def
handle
(
self
,
context
,
sign
,
*
args
):
return
_
Infsign
[
sign
]
return
_
SignedInfinity
[
sign
]
class
DivisionImpossible
(
InvalidOperation
):
"""Cannot perform the division adequately.
...
...
@@ -341,15 +341,15 @@ class Overflow(Inexact, Rounded):
def
handle
(
self
,
context
,
sign
,
*
args
):
if
context
.
rounding
in
(
ROUND_HALF_UP
,
ROUND_HALF_EVEN
,
ROUND_HALF_DOWN
,
ROUND_UP
):
return
_
Infsign
[
sign
]
return
_
SignedInfinity
[
sign
]
if
sign
==
0
:
if
context
.
rounding
==
ROUND_CEILING
:
return
_
Infsign
[
sign
]
return
_
SignedInfinity
[
sign
]
return
_dec_from_triple
(
sign
,
'9'
*
context
.
prec
,
context
.
Emax
-
context
.
prec
+
1
)
if
sign
==
1
:
if
context
.
rounding
==
ROUND_FLOOR
:
return
_
Infsign
[
sign
]
return
_
SignedInfinity
[
sign
]
return
_dec_from_triple
(
sign
,
'9'
*
context
.
prec
,
context
.
Emax
-
context
.
prec
+
1
)
...
...
@@ -1204,12 +1204,12 @@ class Decimal(object):
if
self
.
_isinfinity
():
if
not
other
:
return
context
.
_raise_error
(
InvalidOperation
,
'(+-)INF * 0'
)
return
_
Infsign
[
resultsign
]
return
_
SignedInfinity
[
resultsign
]
if
other
.
_isinfinity
():
if
not
self
:
return
context
.
_raise_error
(
InvalidOperation
,
'0 * (+-)INF'
)
return
_
Infsign
[
resultsign
]
return
_
SignedInfinity
[
resultsign
]
resultexp
=
self
.
_exp
+
other
.
_exp
...
...
@@ -1259,7 +1259,7 @@ class Decimal(object):
return
context
.
_raise_error
(
InvalidOperation
,
'(+-)INF/(+-)INF'
)
if
self
.
_isinfinity
():
return
_
Infsign
[
sign
]
return
_
SignedInfinity
[
sign
]
if
other
.
_isinfinity
():
context
.
_raise_error
(
Clamped
,
'Division by infinity'
)
...
...
@@ -1362,7 +1362,7 @@ class Decimal(object):
ans
=
context
.
_raise_error
(
InvalidOperation
,
'divmod(INF, INF)'
)
return
ans
,
ans
else
:
return
(
_
Infsign
[
sign
],
return
(
_
SignedInfinity
[
sign
],
context
.
_raise_error
(
InvalidOperation
,
'INF
%
x'
))
if
not
other
:
...
...
@@ -1510,7 +1510,7 @@ class Decimal(object):
if
other
.
_isinfinity
():
return
context
.
_raise_error
(
InvalidOperation
,
'INF // INF'
)
else
:
return
_
Infsign
[
self
.
_sign
^
other
.
_sign
]
return
_
SignedInfinity
[
self
.
_sign
^
other
.
_sign
]
if
not
other
:
if
self
:
...
...
@@ -1765,12 +1765,12 @@ class Decimal(object):
if
not
other
:
return
context
.
_raise_error
(
InvalidOperation
,
'INF * 0 in fma'
)
product
=
_
Infsign
[
self
.
_sign
^
other
.
_sign
]
product
=
_
SignedInfinity
[
self
.
_sign
^
other
.
_sign
]
elif
other
.
_exp
==
'F'
:
if
not
self
:
return
context
.
_raise_error
(
InvalidOperation
,
'0 * INF in fma'
)
product
=
_
Infsign
[
self
.
_sign
^
other
.
_sign
]
product
=
_
SignedInfinity
[
self
.
_sign
^
other
.
_sign
]
else
:
product
=
_dec_from_triple
(
self
.
_sign
^
other
.
_sign
,
str
(
int
(
self
.
_int
)
*
int
(
other
.
_int
)),
...
...
@@ -2120,7 +2120,7 @@ class Decimal(object):
if
not
self
:
return
context
.
_raise_error
(
InvalidOperation
,
'0 ** 0'
)
else
:
return
_
Dec_p1
return
_
One
# result has sign 1 iff self._sign is 1 and other is an odd integer
result_sign
=
0
...
...
@@ -2142,19 +2142,19 @@ class Decimal(object):
if
other
.
_sign
==
0
:
return
_dec_from_triple
(
result_sign
,
'0'
,
0
)
else
:
return
_
Infsign
[
result_sign
]
return
_
SignedInfinity
[
result_sign
]
# Inf**(+ve or Inf) = Inf; Inf**(-ve or -Inf) = 0
if
self
.
_isinfinity
():
if
other
.
_sign
==
0
:
return
_
Infsign
[
result_sign
]
return
_
SignedInfinity
[
result_sign
]
else
:
return
_dec_from_triple
(
result_sign
,
'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
==
_
Dec_p1
:
if
self
==
_
One
:
if
other
.
_isinteger
():
# exp = max(self._exp*max(int(other), 0),
# 1-context.prec) but evaluating int(other) directly
...
...
@@ -2187,7 +2187,7 @@ class Decimal(object):
if
(
other
.
_sign
==
0
)
==
(
self_adj
<
0
):
return
_dec_from_triple
(
result_sign
,
'0'
,
0
)
else
:
return
_
Infsign
[
result_sign
]
return
_
SignedInfinity
[
result_sign
]
# from here on, the result always goes through the call
# to _fix at the end of this function.
...
...
@@ -2707,9 +2707,9 @@ class Decimal(object):
"""
# if one is negative and the other is positive, it's easy
if
self
.
_sign
and
not
other
.
_sign
:
return
_
Dec_n1
return
_
NegativeOne
if
not
self
.
_sign
and
other
.
_sign
:
return
_
Dec_p1
return
_
One
sign
=
self
.
_sign
# let's handle both NaN types
...
...
@@ -2719,51 +2719,51 @@ class Decimal(object):
if
self_nan
==
other_nan
:
if
self
.
_int
<
other
.
_int
:
if
sign
:
return
_
Dec_p1
return
_
One
else
:
return
_
Dec_n1
return
_
NegativeOne
if
self
.
_int
>
other
.
_int
:
if
sign
:
return
_
Dec_n1
return
_
NegativeOne
else
:
return
_
Dec_p1
return
_
Dec_0
return
_
One
return
_
Zero
if
sign
:
if
self_nan
==
1
:
return
_
Dec_n1
return
_
NegativeOne
if
other_nan
==
1
:
return
_
Dec_p1
return
_
One
if
self_nan
==
2
:
return
_
Dec_n1
return
_
NegativeOne
if
other_nan
==
2
:
return
_
Dec_p1
return
_
One
else
:
if
self_nan
==
1
:
return
_
Dec_p1
return
_
One
if
other_nan
==
1
:
return
_
Dec_n1
return
_
NegativeOne
if
self_nan
==
2
:
return
_
Dec_p1
return
_
One
if
other_nan
==
2
:
return
_
Dec_n1
return
_
NegativeOne
if
self
<
other
:
return
_
Dec_n1
return
_
NegativeOne
if
self
>
other
:
return
_
Dec_p1
return
_
One
if
self
.
_exp
<
other
.
_exp
:
if
sign
:
return
_
Dec_p1
return
_
One
else
:
return
_
Dec_n1
return
_
NegativeOne
if
self
.
_exp
>
other
.
_exp
:
if
sign
:
return
_
Dec_n1
return
_
NegativeOne
else
:
return
_
Dec_p1
return
_
Dec_0
return
_
One
return
_
Zero
def
compare_total_mag
(
self
,
other
):
...
...
@@ -2804,11 +2804,11 @@ class Decimal(object):
# exp(-Infinity) = 0
if
self
.
_isinfinity
()
==
-
1
:
return
_
Dec_0
return
_
Zero
# exp(0) = 1
if
not
self
:
return
_
Dec_p1
return
_
One
# exp(Infinity) = Infinity
if
self
.
_isinfinity
()
==
1
:
...
...
@@ -2960,15 +2960,15 @@ class Decimal(object):
# ln(0.0) == -Infinity
if
not
self
:
return
_
negInf
return
_
NegativeInfinity
# ln(Infinity) = Infinity
if
self
.
_isinfinity
()
==
1
:
return
_Inf
return
_Inf
inity
# ln(1.0) == 0.0
if
self
==
_
Dec_p1
:
return
_
Dec_0
if
self
==
_
One
:
return
_
Zero
# ln(negative) raises InvalidOperation
if
self
.
_sign
==
1
:
...
...
@@ -3040,11 +3040,11 @@ class Decimal(object):
# log10(0.0) == -Infinity
if
not
self
:
return
_
negInf
return
_
NegativeInfinity
# log10(Infinity) = Infinity
if
self
.
_isinfinity
()
==
1
:
return
_Inf
return
_Inf
inity
# log10(negative or -Infinity) raises InvalidOperation
if
self
.
_sign
==
1
:
...
...
@@ -3096,7 +3096,7 @@ class Decimal(object):
# logb(+/-Inf) = +Inf
if
self
.
_isinfinity
():
return
_Inf
return
_Inf
inity
# logb(0) = -Inf, DivisionByZero
if
not
self
:
...
...
@@ -3253,7 +3253,7 @@ class Decimal(object):
return
ans
if
self
.
_isinfinity
()
==
-
1
:
return
_
negInf
return
_
NegativeInfinity
if
self
.
_isinfinity
()
==
1
:
return
_dec_from_triple
(
0
,
'9'
*
context
.
prec
,
context
.
Etop
())
...
...
@@ -3276,7 +3276,7 @@ class Decimal(object):
return
ans
if
self
.
_isinfinity
()
==
1
:
return
_Inf
return
_Inf
inity
if
self
.
_isinfinity
()
==
-
1
:
return
_dec_from_triple
(
1
,
'9'
*
context
.
prec
,
context
.
Etop
())
...
...
@@ -5540,15 +5540,15 @@ def _format_align(body, spec_dict):
##### Useful Constants (internal use only) ################################
# Reusable defaults
_Inf
=
Decimal
(
'Inf'
)
_
negInf
=
Decimal
(
'-Inf'
)
_Inf
inity
=
Decimal
(
'Inf'
)
_
NegativeInfinity
=
Decimal
(
'-Inf'
)
_NaN
=
Decimal
(
'NaN'
)
_
Dec_0
=
Decimal
(
0
)
_
Dec_p1
=
Decimal
(
1
)
_
Dec_n1
=
Decimal
(
-
1
)
_
Zero
=
Decimal
(
0
)
_
One
=
Decimal
(
1
)
_
NegativeOne
=
Decimal
(
-
1
)
# _
Infsign
[sign] is infinity w/ that sign
_
Infsign
=
(
_Inf
,
_negInf
)
# _
SignedInfinity
[sign] is infinity w/ that sign
_
SignedInfinity
=
(
_Infinity
,
_NegativeInfinity
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment