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
fe427895
Kaydet (Commit)
fe427895
authored
Ock 03, 2009
tarafından
Georg Brandl
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Manually merge r68095,68186,68187,68188,68190 from 2.6 branch.
üst
c63785db
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
25 additions
and
8 deletions
+25
-8
decimal.rst
Doc/library/decimal.rst
+8
-7
fractions.py
Lib/fractions.py
+1
-1
heapq.py
Lib/heapq.py
+8
-0
test_fractions.py
Lib/test/test_fractions.py
+2
-0
NEWS
Misc/NEWS
+6
-0
No files found.
Doc/library/decimal.rst
Dosyayı görüntüle @
fe427895
...
@@ -1923,13 +1923,14 @@ suggest, so we trap :const:`Inexact` to signal a need for more precision:
...
@@ -1923,13 +1923,14 @@ suggest, so we trap :const:`Inexact` to signal a need for more precision:
def float_to_decimal(f):
def float_to_decimal(f):
"Convert a floating point number to a Decimal with no loss of information"
"Convert a floating point number to a Decimal with no loss of information"
n, d = f.as_integer_ratio()
n, d = f.as_integer_ratio()
with localcontext() as ctx:
numerator, denominator = Decimal(n), Decimal(d)
ctx.traps[Inexact] = True
ctx = Context(prec=60)
while True:
result = ctx.divide(numerator, denominator)
try:
while ctx.flags[Inexact]:
return Decimal(n) / Decimal(d)
ctx.flags[Inexact] = False
except Inexact:
ctx.prec *= 2
ctx.prec += 1
result = ctx.divide(numerator, denominator)
return result
.. doctest::
.. doctest::
...
...
Lib/fractions.py
Dosyayı görüntüle @
fe427895
...
@@ -111,7 +111,7 @@ class Fraction(Rational):
...
@@ -111,7 +111,7 @@ class Fraction(Rational):
"""
"""
if
isinstance
(
f
,
numbers
.
Integral
):
if
isinstance
(
f
,
numbers
.
Integral
):
f
=
float
(
f
)
return
cls
(
f
)
elif
not
isinstance
(
f
,
float
):
elif
not
isinstance
(
f
,
float
):
raise
TypeError
(
"
%
s.from_float() only takes floats, not
%
r (
%
s)"
%
raise
TypeError
(
"
%
s.from_float() only takes floats, not
%
r (
%
s)"
%
(
cls
.
__name__
,
f
,
type
(
f
)
.
__name__
))
(
cls
.
__name__
,
f
,
type
(
f
)
.
__name__
))
...
...
Lib/heapq.py
Dosyayı görüntüle @
fe427895
...
@@ -354,6 +354,10 @@ def nsmallest(n, iterable, key=None):
...
@@ -354,6 +354,10 @@ def nsmallest(n, iterable, key=None):
Equivalent to: sorted(iterable, key=key)[:n]
Equivalent to: sorted(iterable, key=key)[:n]
"""
"""
if
key
is
None
:
it
=
izip
(
iterable
,
count
())
# decorate
result
=
_nsmallest
(
n
,
it
)
return
map
(
itemgetter
(
0
),
result
)
# undecorate
in1
,
in2
=
tee
(
iterable
)
in1
,
in2
=
tee
(
iterable
)
it
=
izip
(
imap
(
key
,
in1
),
count
(),
in2
)
# decorate
it
=
izip
(
imap
(
key
,
in1
),
count
(),
in2
)
# decorate
result
=
_nsmallest
(
n
,
it
)
result
=
_nsmallest
(
n
,
it
)
...
@@ -365,6 +369,10 @@ def nlargest(n, iterable, key=None):
...
@@ -365,6 +369,10 @@ def nlargest(n, iterable, key=None):
Equivalent to: sorted(iterable, key=key, reverse=True)[:n]
Equivalent to: sorted(iterable, key=key, reverse=True)[:n]
"""
"""
if
key
is
None
:
it
=
izip
(
iterable
,
imap
(
neg
,
count
()))
# decorate
result
=
_nlargest
(
n
,
it
)
return
map
(
itemgetter
(
0
),
result
)
# undecorate
in1
,
in2
=
tee
(
iterable
)
in1
,
in2
=
tee
(
iterable
)
it
=
izip
(
imap
(
key
,
in1
),
imap
(
neg
,
count
()),
in2
)
# decorate
it
=
izip
(
imap
(
key
,
in1
),
imap
(
neg
,
count
()),
in2
)
# decorate
result
=
_nlargest
(
n
,
it
)
result
=
_nlargest
(
n
,
it
)
...
...
Lib/test/test_fractions.py
Dosyayı görüntüle @
fe427895
...
@@ -139,6 +139,8 @@ class FractionTest(unittest.TestCase):
...
@@ -139,6 +139,8 @@ class FractionTest(unittest.TestCase):
def
testFromFloat
(
self
):
def
testFromFloat
(
self
):
self
.
assertRaises
(
TypeError
,
F
.
from_float
,
3
+
4
j
)
self
.
assertRaises
(
TypeError
,
F
.
from_float
,
3
+
4
j
)
self
.
assertEquals
((
10
,
1
),
_components
(
F
.
from_float
(
10
)))
self
.
assertEquals
((
10
,
1
),
_components
(
F
.
from_float
(
10
)))
bigint
=
1234567890123456789
self
.
assertEquals
((
bigint
,
1
),
_components
(
F
.
from_float
(
bigint
)))
self
.
assertEquals
((
0
,
1
),
_components
(
F
.
from_float
(
-
0.0
)))
self
.
assertEquals
((
0
,
1
),
_components
(
F
.
from_float
(
-
0.0
)))
self
.
assertEquals
((
10
,
1
),
_components
(
F
.
from_float
(
10.0
)))
self
.
assertEquals
((
10
,
1
),
_components
(
F
.
from_float
(
10.0
)))
self
.
assertEquals
((
-
5
,
2
),
_components
(
F
.
from_float
(
-
2.5
)))
self
.
assertEquals
((
-
5
,
2
),
_components
(
F
.
from_float
(
-
2.5
)))
...
...
Misc/NEWS
Dosyayı görüntüle @
fe427895
...
@@ -127,6 +127,12 @@ Library
...
@@ -127,6 +127,12 @@ Library
- Issue #4646: distutils was choking on empty options arg in the setup
- Issue #4646: distutils was choking on empty options arg in the setup
function. Original patch by Thomas Heller.
function. Original patch by Thomas Heller.
- Fractions.from_float() no longer loses precision for integers too big to
cast as floats.
- Issue 4790: The nsmallest() and nlargest() functions in the heapq module
did unnecessary work in the common case where no key function was specified.
- Issue #3767: Convert Tk object to string in tkColorChooser.
- Issue #3767: Convert Tk object to string in tkColorChooser.
- Issue #3248: Allow placing ScrolledText in a PanedWindow.
- Issue #3248: Allow placing ScrolledText in a PanedWindow.
...
...
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