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
c2155835
Kaydet (Commit)
c2155835
authored
Ock 05, 2008
tarafından
Jeffrey Yasskin
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Make math.floor and math.ceil return ints instead of floats.
üst
d348b258
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
21 additions
and
6 deletions
+21
-6
test_math.py
Lib/test/test_math.py
+2
-0
mathmodule.c
Modules/mathmodule.c
+19
-6
No files found.
Lib/test/test_math.py
Dosyayı görüntüle @
c2155835
...
@@ -51,6 +51,7 @@ class MathTests(unittest.TestCase):
...
@@ -51,6 +51,7 @@ class MathTests(unittest.TestCase):
def
testCeil
(
self
):
def
testCeil
(
self
):
self
.
assertRaises
(
TypeError
,
math
.
ceil
)
self
.
assertRaises
(
TypeError
,
math
.
ceil
)
self
.
assertEquals
(
int
,
type
(
math
.
ceil
(
0.5
)))
self
.
ftest
(
'ceil(0.5)'
,
math
.
ceil
(
0.5
),
1
)
self
.
ftest
(
'ceil(0.5)'
,
math
.
ceil
(
0.5
),
1
)
self
.
ftest
(
'ceil(1.0)'
,
math
.
ceil
(
1.0
),
1
)
self
.
ftest
(
'ceil(1.0)'
,
math
.
ceil
(
1.0
),
1
)
self
.
ftest
(
'ceil(1.5)'
,
math
.
ceil
(
1.5
),
2
)
self
.
ftest
(
'ceil(1.5)'
,
math
.
ceil
(
1.5
),
2
)
...
@@ -103,6 +104,7 @@ class MathTests(unittest.TestCase):
...
@@ -103,6 +104,7 @@ class MathTests(unittest.TestCase):
def
testFloor
(
self
):
def
testFloor
(
self
):
self
.
assertRaises
(
TypeError
,
math
.
floor
)
self
.
assertRaises
(
TypeError
,
math
.
floor
)
self
.
assertEquals
(
int
,
type
(
math
.
floor
(
0.5
)))
self
.
ftest
(
'floor(0.5)'
,
math
.
floor
(
0.5
),
0
)
self
.
ftest
(
'floor(0.5)'
,
math
.
floor
(
0.5
),
0
)
self
.
ftest
(
'floor(1.0)'
,
math
.
floor
(
1.0
),
1
)
self
.
ftest
(
'floor(1.0)'
,
math
.
floor
(
1.0
),
1
)
self
.
ftest
(
'floor(1.5)'
,
math
.
floor
(
1.5
),
1
)
self
.
ftest
(
'floor(1.5)'
,
math
.
floor
(
1.5
),
1
)
...
...
Modules/mathmodule.c
Dosyayı görüntüle @
c2155835
...
@@ -48,7 +48,8 @@ is_error(double x)
...
@@ -48,7 +48,8 @@ is_error(double x)
}
}
static
PyObject
*
static
PyObject
*
math_1
(
PyObject
*
arg
,
double
(
*
func
)
(
double
))
math_1_to_whatever
(
PyObject
*
arg
,
double
(
*
func
)
(
double
),
PyObject
*
(
*
from_double_func
)
(
double
))
{
{
double
x
=
PyFloat_AsDouble
(
arg
);
double
x
=
PyFloat_AsDouble
(
arg
);
if
(
x
==
-
1
.
0
&&
PyErr_Occurred
())
if
(
x
==
-
1
.
0
&&
PyErr_Occurred
())
...
@@ -61,7 +62,19 @@ math_1(PyObject *arg, double (*func) (double))
...
@@ -61,7 +62,19 @@ math_1(PyObject *arg, double (*func) (double))
if
(
errno
&&
is_error
(
x
))
if
(
errno
&&
is_error
(
x
))
return
NULL
;
return
NULL
;
else
else
return
PyFloat_FromDouble
(
x
);
return
(
*
from_double_func
)(
x
);
}
static
PyObject
*
math_1
(
PyObject
*
arg
,
double
(
*
func
)
(
double
))
{
return
math_1_to_whatever
(
arg
,
func
,
PyFloat_FromDouble
);
}
static
PyObject
*
math_1_to_int
(
PyObject
*
arg
,
double
(
*
func
)
(
double
))
{
return
math_1_to_whatever
(
arg
,
func
,
PyLong_FromDouble
);
}
}
static
PyObject
*
static
PyObject
*
...
@@ -120,13 +133,13 @@ static PyObject * math_ceil(PyObject *self, PyObject *number) {
...
@@ -120,13 +133,13 @@ static PyObject * math_ceil(PyObject *self, PyObject *number) {
method
=
_PyType_Lookup
(
Py_TYPE
(
number
),
ceil_str
);
method
=
_PyType_Lookup
(
Py_TYPE
(
number
),
ceil_str
);
if
(
method
==
NULL
)
if
(
method
==
NULL
)
return
math_1
(
number
,
ceil
);
return
math_1
_to_int
(
number
,
ceil
);
else
else
return
PyObject_CallFunction
(
method
,
"O"
,
number
);
return
PyObject_CallFunction
(
method
,
"O"
,
number
);
}
}
PyDoc_STRVAR
(
math_ceil_doc
,
PyDoc_STRVAR
(
math_ceil_doc
,
"ceil(x)
\n\n
Return the ceiling of x as a
floa
t.
\n
"
"ceil(x)
\n\n
Return the ceiling of x as a
n in
t.
\n
"
"This is the smallest integral value >= x."
);
"This is the smallest integral value >= x."
);
FUNC1
(
cos
,
cos
,
FUNC1
(
cos
,
cos
,
...
@@ -160,13 +173,13 @@ static PyObject * math_floor(PyObject *self, PyObject *number) {
...
@@ -160,13 +173,13 @@ static PyObject * math_floor(PyObject *self, PyObject *number) {
method
=
_PyType_Lookup
(
Py_TYPE
(
number
),
floor_str
);
method
=
_PyType_Lookup
(
Py_TYPE
(
number
),
floor_str
);
if
(
method
==
NULL
)
if
(
method
==
NULL
)
return
math_1
(
number
,
floor
);
return
math_1_to_int
(
number
,
floor
);
else
else
return
PyObject_CallFunction
(
method
,
"O"
,
number
);
return
PyObject_CallFunction
(
method
,
"O"
,
number
);
}
}
PyDoc_STRVAR
(
math_floor_doc
,
PyDoc_STRVAR
(
math_floor_doc
,
"floor(x)
\n\n
Return the floor of x as a
floa
t.
\n
"
"floor(x)
\n\n
Return the floor of x as a
n in
t.
\n
"
"This is the largest integral value <= x."
);
"This is the largest integral value <= x."
);
FUNC2
(
fmod
,
fmod
,
FUNC2
(
fmod
,
fmod
,
...
...
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