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
605ed024
Kaydet (Commit)
605ed024
authored
Kas 24, 2004
tarafından
Raymond Hettinger
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
SF bug #1071588 coercing decimal to int doesn't work between -1 and 1
üst
8f2c4eed
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
11 additions
and
11 deletions
+11
-11
decimal.py
Lib/decimal.py
+7
-7
test_decimal.py
Lib/test/test_decimal.py
+4
-4
No files found.
Lib/decimal.py
Dosyayı görüntüle @
605ed024
...
@@ -1410,14 +1410,14 @@ class Decimal(object):
...
@@ -1410,14 +1410,14 @@ class Decimal(object):
return
context
.
_raise_error
(
InvalidContext
)
return
context
.
_raise_error
(
InvalidContext
)
elif
self
.
_isinfinity
():
elif
self
.
_isinfinity
():
raise
OverflowError
,
"Cannot convert infinity to long"
raise
OverflowError
,
"Cannot convert infinity to long"
if
not
self
:
return
0
sign
=
'-'
*
self
.
_sign
if
self
.
_exp
>=
0
:
if
self
.
_exp
>=
0
:
s
=
sign
+
''
.
join
(
map
(
str
,
self
.
_int
))
+
'0'
*
self
.
_exp
s
=
''
.
join
(
map
(
str
,
self
.
_int
))
+
'0'
*
self
.
_exp
return
int
(
s
)
else
:
s
=
sign
+
''
.
join
(
map
(
str
,
self
.
_int
))[:
self
.
_exp
]
s
=
''
.
join
(
map
(
str
,
self
.
_int
))[:
self
.
_exp
]
return
int
(
s
)
if
s
==
''
:
s
=
'0'
sign
=
'-'
*
self
.
_sign
return
int
(
sign
+
s
)
def
__long__
(
self
):
def
__long__
(
self
):
"""Converts to a long.
"""Converts to a long.
...
...
Lib/test/test_decimal.py
Dosyayı görüntüle @
605ed024
...
@@ -967,13 +967,13 @@ class DecimalPythonAPItests(unittest.TestCase):
...
@@ -967,13 +967,13 @@ class DecimalPythonAPItests(unittest.TestCase):
self
.
assertEqual
(
d
,
e
)
self
.
assertEqual
(
d
,
e
)
def
test_int
(
self
):
def
test_int
(
self
):
data
=
'1.0 1.1 1.9 2.0 0.0 -1.0 -1.1 -1.9 -2.0'
.
split
()
for
x
in
range
(
-
250
,
250
):
for
s
in
data
:
s
=
'
%0.2
f'
%
(
x
/
100.0
)
# should work the same as for floats
# should work the same as for floats
self
.
assertEqual
(
int
(
Decimal
(
s
)),
int
(
float
(
s
)))
self
.
assertEqual
(
int
(
Decimal
(
s
)),
int
(
float
(
s
)))
# should work the same as
ROUND_DOWN
# should work the same as
to_integral in the ROUND_DOWN mode
d
=
Decimal
(
s
)
d
=
Decimal
(
s
)
r
=
Context
(
prec
=
1
,
rounding
=
ROUND_DOWN
)
.
create_decimal
(
s
)
r
=
d
.
to_integral
(
ROUND_DOWN
)
self
.
assertEqual
(
Decimal
(
int
(
d
)),
r
)
self
.
assertEqual
(
Decimal
(
int
(
d
)),
r
)
class
ContextAPItests
(
unittest
.
TestCase
):
class
ContextAPItests
(
unittest
.
TestCase
):
...
...
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