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
13e05de9
Kaydet (Commit)
13e05de9
authored
Agu 23, 2007
tarafından
Guido van Rossum
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Fix math.ceil() and math.floor() to fall back to __ceil__ and __floor__
methods (respectively). With Keir Mierle.
üst
2fa33db1
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
70 additions
and
6 deletions
+70
-6
test_math.py
Lib/test/test_math.py
+26
-0
mathmodule.c
Modules/mathmodule.c
+44
-6
No files found.
Lib/test/test_math.py
Dosyayı görüntüle @
13e05de9
...
...
@@ -58,6 +58,19 @@ class MathTests(unittest.TestCase):
self
.
ftest
(
'ceil(-1.0)'
,
math
.
ceil
(
-
1.0
),
-
1
)
self
.
ftest
(
'ceil(-1.5)'
,
math
.
ceil
(
-
1.5
),
-
1
)
class
TestCeil
:
def
__ceil__
(
self
):
return
42
class
TestNoCeil
:
pass
self
.
ftest
(
'ceil(TestCeil())'
,
math
.
ceil
(
TestCeil
()),
42
)
self
.
assertRaises
(
TypeError
,
math
.
ceil
,
TestNoCeil
())
t
=
TestNoCeil
()
t
.
__ceil__
=
lambda
*
args
:
args
self
.
assertRaises
(
TypeError
,
math
.
ceil
,
t
)
self
.
assertRaises
(
TypeError
,
math
.
ceil
,
t
,
0
)
def
testCos
(
self
):
self
.
assertRaises
(
TypeError
,
math
.
cos
)
self
.
ftest
(
'cos(-pi/2)'
,
math
.
cos
(
-
math
.
pi
/
2
),
0
)
...
...
@@ -101,6 +114,19 @@ class MathTests(unittest.TestCase):
self
.
ftest
(
'floor(1.23e167)'
,
math
.
floor
(
1.23e167
),
1.23e167
)
self
.
ftest
(
'floor(-1.23e167)'
,
math
.
floor
(
-
1.23e167
),
-
1.23e167
)
class
TestFloor
:
def
__floor__
(
self
):
return
42
class
TestNoFloor
:
pass
self
.
ftest
(
'floor(TestFloor())'
,
math
.
floor
(
TestFloor
()),
42
)
self
.
assertRaises
(
TypeError
,
math
.
floor
,
TestNoFloor
())
t
=
TestNoFloor
()
t
.
__floor__
=
lambda
*
args
:
args
self
.
assertRaises
(
TypeError
,
math
.
floor
,
t
)
self
.
assertRaises
(
TypeError
,
math
.
floor
,
t
,
0
)
def
testFmod
(
self
):
self
.
assertRaises
(
TypeError
,
math
.
fmod
)
self
.
ftest
(
'fmod(10,1)'
,
math
.
fmod
(
10
,
1
),
0
)
...
...
Modules/mathmodule.c
Dosyayı görüntüle @
13e05de9
...
...
@@ -107,9 +107,28 @@ FUNC1(atan, atan,
FUNC2
(
atan2
,
atan2
,
"atan2(y, x)
\n\n
Return the arc tangent (measured in radians) of y/x.
\n
"
"Unlike atan(y/x), the signs of both x and y are considered."
)
FUNC1
(
ceil
,
ceil
,
"ceil(x)
\n\n
Return the ceiling of x as a float.
\n
"
"This is the smallest integral value >= x."
)
static
PyObject
*
math_ceil
(
PyObject
*
self
,
PyObject
*
number
)
{
static
PyObject
*
ceil_str
=
NULL
;
PyObject
*
method
;
if
(
ceil_str
==
NULL
)
{
ceil_str
=
PyUnicode_FromString
(
"__ceil__"
);
if
(
ceil_str
==
NULL
)
return
NULL
;
}
method
=
_PyType_Lookup
(
Py_Type
(
number
),
ceil_str
);
if
(
method
==
NULL
)
return
math_1
(
number
,
ceil
);
else
return
PyObject_CallFunction
(
method
,
"O"
,
number
);
}
PyDoc_STRVAR
(
math_ceil_doc
,
"ceil(x)
\n\n
Return the ceiling of x as a float.
\n
"
"This is the smallest integral value >= x."
);
FUNC1
(
cos
,
cos
,
"cos(x)
\n\n
Return the cosine of x (measured in radians)."
)
FUNC1
(
cosh
,
cosh
,
...
...
@@ -118,9 +137,28 @@ FUNC1(exp, exp,
"exp(x)
\n\n
Return e raised to the power of x."
)
FUNC1
(
fabs
,
fabs
,
"fabs(x)
\n\n
Return the absolute value of the float x."
)
FUNC1
(
floor
,
floor
,
"floor(x)
\n\n
Return the floor of x as a float.
\n
"
"This is the largest integral value <= x."
)
static
PyObject
*
math_floor
(
PyObject
*
self
,
PyObject
*
number
)
{
static
PyObject
*
floor_str
=
NULL
;
PyObject
*
method
;
if
(
floor_str
==
NULL
)
{
floor_str
=
PyUnicode_FromString
(
"__floor__"
);
if
(
floor_str
==
NULL
)
return
NULL
;
}
method
=
_PyType_Lookup
(
Py_Type
(
number
),
floor_str
);
if
(
method
==
NULL
)
return
math_1
(
number
,
floor
);
else
return
PyObject_CallFunction
(
method
,
"O"
,
number
);
}
PyDoc_STRVAR
(
math_floor_doc
,
"floor(x)
\n\n
Return the floor of x as a float.
\n
"
"This is the largest integral value <= x."
);
FUNC2
(
fmod
,
fmod
,
"fmod(x,y)
\n\n
Return fmod(x, y), according to platform C."
" x % y may differ."
)
...
...
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