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
cb39d1f4
Kaydet (Commit)
cb39d1f4
authored
Nis 15, 2015
tarafından
Steve Dower
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Issue 19933: Provide default argument for ndigits in round. Patch by Vajrasky Kok.
üst
807b80d4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
16 additions
and
4 deletions
+16
-4
functions.rst
Doc/library/functions.rst
+2
-2
test_float.py
Lib/test/test_float.py
+8
-0
NEWS
Misc/NEWS
+3
-0
floatobject.c
Objects/floatobject.c
+3
-2
No files found.
Doc/library/functions.rst
Dosyayı görüntüle @
cb39d1f4
...
...
@@ -1225,8 +1225,8 @@ are always available. They are listed here in alphabetical order.
.. function:: round(number[, ndigits])
Return the floating point value *number* rounded to *ndigits* digits after
the decimal point. If *ndigits* is omitted, it
defaults to zero. Delegates
to ``number.__round__(ndigits)``.
the decimal point. If *ndigits* is omitted, it
returns the nearest integer
to
its input. Delegates to
``number.__round__(ndigits)``.
For the built-in types supporting :func:`round`, values are rounded to the
closest multiple of 10 to the power minus *ndigits*; if two multiples are
...
...
Lib/test/test_float.py
Dosyayı görüntüle @
cb39d1f4
...
...
@@ -773,6 +773,14 @@ class RoundTestCase(unittest.TestCase):
test
(
sfmt
,
NAN
,
' nan'
)
test
(
sfmt
,
-
NAN
,
' nan'
)
def
test_None_ndigits
(
self
):
for
x
in
round
(
1.23
),
round
(
1.23
,
None
),
round
(
1.23
,
ndigits
=
None
):
self
.
assertEqual
(
x
,
1
)
self
.
assertIsInstance
(
x
,
int
)
for
x
in
round
(
1.78
),
round
(
1.78
,
None
),
round
(
1.78
,
ndigits
=
None
):
self
.
assertEqual
(
x
,
2
)
self
.
assertIsInstance
(
x
,
int
)
# Beginning with Python 2.6 float has cross platform compatible
# ways to create and represent inf and nan
...
...
Misc/NEWS
Dosyayı görüntüle @
cb39d1f4
...
...
@@ -36,6 +36,9 @@ Core and Builtins
Library
-------
- Issue 19933: Provide default argument for ndigits in round. Patch by
Vajrasky Kok.
- Issue #23193: Add a numeric_owner parameter to
tarfile.TarFile.extract and tarfile.TarFile.extractall. Patch by
Michael Vogt and Eric Smith.
...
...
Objects/floatobject.c
Dosyayı görüntüle @
cb39d1f4
...
...
@@ -986,8 +986,9 @@ float_round(PyObject *v, PyObject *args)
x
=
PyFloat_AsDouble
(
v
);
if
(
!
PyArg_ParseTuple
(
args
,
"|O"
,
&
o_ndigits
))
return
NULL
;
if
(
o_ndigits
==
NULL
)
{
/* single-argument round: round to nearest integer */
if
(
o_ndigits
==
NULL
||
o_ndigits
==
Py_None
)
{
/* single-argument round or with None ndigits:
* round to nearest integer */
rounded
=
round
(
x
);
if
(
fabs
(
x
-
rounded
)
==
0
.
5
)
/* halfway case: round to even */
...
...
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