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
62edb715
Kaydet (Commit)
62edb715
authored
Ara 03, 2007
tarafından
Facundo Batista
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Speedup and cleaning of __str__. Thanks Mark Dickinson.
üst
0f6d4e6c
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
41 additions
and
71 deletions
+41
-71
decimal.py
Lib/decimal.py
+41
-71
No files found.
Lib/decimal.py
Dosyayı görüntüle @
62edb715
...
...
@@ -837,81 +837,51 @@ class Decimal(object):
Captures all of the information in the underlying representation.
"""
sign
=
[
''
,
'-'
][
self
.
_sign
]
if
self
.
_is_special
:
if
self
.
_isnan
():
minus
=
'-'
*
self
.
_sign
if
self
.
_int
==
'0'
:
info
=
''
else
:
info
=
self
.
_int
if
self
.
_isnan
()
==
2
:
return
minus
+
'sNaN'
+
info
return
minus
+
'NaN'
+
info
if
self
.
_isinfinity
():
minus
=
'-'
*
self
.
_sign
return
minus
+
'Infinity'
if
context
is
None
:
context
=
getcontext
()
tmp
=
list
(
self
.
_int
)
numdigits
=
len
(
self
.
_int
)
leftdigits
=
self
.
_exp
+
numdigits
if
eng
and
not
self
:
# self = 0eX wants 0[.0[0]]eY, not [[0]0]0eY
if
self
.
_exp
<
0
and
self
.
_exp
>=
-
6
:
# short, no need for e/E
s
=
'-'
*
self
.
_sign
+
'0.'
+
'0'
*
(
abs
(
self
.
_exp
))
return
s
# exp is closest mult. of 3 >= self._exp
exp
=
((
self
.
_exp
-
1
)
//
3
+
1
)
*
3
if
exp
!=
self
.
_exp
:
s
=
'0.'
+
'0'
*
(
exp
-
self
.
_exp
)
else
:
s
=
'0'
if
exp
!=
0
:
if
context
.
capitals
:
s
+=
'E'
else
:
s
+=
'e'
if
exp
>
0
:
s
+=
'+'
# 0.0e+3, not 0.0e3
s
+=
str
(
exp
)
s
=
'-'
*
self
.
_sign
+
s
return
s
if
eng
:
dotplace
=
(
leftdigits
-
1
)
%
3
+
1
adjexp
=
leftdigits
-
1
-
(
leftdigits
-
1
)
%
3
else
:
adjexp
=
leftdigits
-
1
if
self
.
_exp
==
'F'
:
return
sign
+
'Infinity'
elif
self
.
_exp
==
'n'
:
return
sign
+
'NaN'
+
self
.
_int
else
:
# self._exp == 'N'
return
sign
+
'sNaN'
+
self
.
_int
# number of digits of self._int to left of decimal point
leftdigits
=
self
.
_exp
+
len
(
self
.
_int
)
# dotplace is number of digits of self._int to the left of the
# decimal point in the mantissa of the output string (that is,
# after adjusting the exponent)
if
self
.
_exp
<=
0
and
leftdigits
>
-
6
:
# no exponent required
dotplace
=
leftdigits
elif
not
eng
:
# usual scientific notation: 1 digit on left of the point
dotplace
=
1
if
self
.
_exp
==
0
:
pass
elif
self
.
_exp
<
0
and
adjexp
>=
0
:
tmp
.
insert
(
leftdigits
,
'.'
)
elif
self
.
_exp
<
0
and
adjexp
>=
-
6
:
tmp
[
0
:
0
]
=
[
'0'
]
*
int
(
-
leftdigits
)
tmp
.
insert
(
0
,
'0.'
)
elif
self
.
_int
==
'0'
:
# engineering notation, zero
dotplace
=
(
leftdigits
+
1
)
%
3
-
1
else
:
if
numdigits
>
dotplace
:
tmp
.
insert
(
dotplace
,
'.'
)
elif
numdigits
<
dotplace
:
tmp
.
extend
([
'0'
]
*
(
dotplace
-
numdigits
))
if
adjexp
:
if
not
context
.
capitals
:
tmp
.
append
(
'e'
)
else
:
tmp
.
append
(
'E'
)
if
adjexp
>
0
:
tmp
.
append
(
'+'
)
tmp
.
append
(
str
(
adjexp
))
if
eng
:
while
tmp
[
0
:
1
]
==
[
'0'
]:
tmp
[
0
:
1
]
=
[]
if
len
(
tmp
)
==
0
or
tmp
[
0
]
==
'.'
or
tmp
[
0
]
.
lower
()
==
'e'
:
tmp
[
0
:
0
]
=
[
'0'
]
if
self
.
_sign
:
tmp
.
insert
(
0
,
'-'
)
# engineering notation, nonzero
dotplace
=
(
leftdigits
-
1
)
%
3
+
1
if
dotplace
<=
0
:
intpart
=
'0'
fracpart
=
'.'
+
'0'
*
(
-
dotplace
)
+
self
.
_int
elif
dotplace
>=
len
(
self
.
_int
):
intpart
=
self
.
_int
+
'0'
*
(
dotplace
-
len
(
self
.
_int
))
fracpart
=
''
else
:
intpart
=
self
.
_int
[:
dotplace
]
fracpart
=
'.'
+
self
.
_int
[
dotplace
:]
if
leftdigits
==
dotplace
:
exp
=
''
else
:
if
context
is
None
:
context
=
getcontext
()
exp
=
[
'e'
,
'E'
][
context
.
capitals
]
+
"
%+
d"
%
(
leftdigits
-
dotplace
)
return
''
.
join
(
tmp
)
return
sign
+
intpart
+
fracpart
+
exp
def
to_eng_string
(
self
,
context
=
None
):
"""Convert to engineering-type string.
...
...
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