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
ae211f9a
Kaydet (Commit)
ae211f9a
authored
Agu 22, 2007
tarafından
Alex Martelli
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Implement the round functionality for PEP 3141, and add tests for it.
üst
1dd46a04
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
39 additions
and
2 deletions
+39
-2
test_builtin.py
Lib/test/test_builtin.py
+13
-0
bltinmodule.c
Python/bltinmodule.c
+26
-2
No files found.
Lib/test/test_builtin.py
Dosyayı görüntüle @
ae211f9a
...
...
@@ -1474,6 +1474,19 @@ class BuiltinTest(unittest.TestCase):
self
.
assertRaises
(
TypeError
,
round
)
# test generic rounding delegation for reals
class
TestRound
:
def
__round__
(
self
):
return
23
class
TestNoRound
:
pass
self
.
assertEqual
(
round
(
TestRound
()),
23
)
self
.
assertRaises
(
TypeError
,
round
,
1
,
2
,
3
)
self
.
assertRaises
(
TypeError
,
round
,
TestNoRound
())
def
test_setattr
(
self
):
setattr
(
sys
,
'spam'
,
1
)
self
.
assertEqual
(
sys
.
spam
,
1
)
...
...
Python/bltinmodule.c
Dosyayı görüntüle @
ae211f9a
...
...
@@ -1378,10 +1378,34 @@ builtin_round(PyObject *self, PyObject *args, PyObject *kwds)
int
ndigits
=
0
;
int
i
;
static
char
*
kwlist
[]
=
{
"number"
,
"ndigits"
,
0
};
PyObject
*
real
;
if
(
!
PyArg_ParseTupleAndKeywords
(
args
,
kwds
,
"
d
|i:round"
,
kwlist
,
&
number
,
&
ndigits
))
if
(
!
PyArg_ParseTupleAndKeywords
(
args
,
kwds
,
"
O
|i:round"
,
kwlist
,
&
real
,
&
ndigits
))
return
NULL
;
if
(
ndigits
==
0
)
{
PyObject
*
res
;
PyObject
*
d
=
PyObject_GetAttrString
(
real
,
"__round__"
);
if
(
d
==
NULL
&&
!
PyFloat_Check
(
real
))
{
PyErr_SetString
(
PyExc_TypeError
,
"round() argument must have __round__ attribute or be a float"
);
return
NULL
;
}
if
(
d
==
NULL
)
{
PyErr_Clear
();
}
else
{
res
=
PyObject_CallFunction
(
d
,
""
);
Py_DECREF
(
d
);
return
res
;
}
}
else
if
(
!
PyFloat_Check
(
real
))
{
PyErr_SetString
(
PyExc_TypeError
,
"round() argument must have __round__ attribute or be a float"
);
return
NULL
;
}
number
=
PyFloat_AsDouble
(
real
);
f
=
1
.
0
;
i
=
abs
(
ndigits
);
while
(
--
i
>=
0
)
...
...
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