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
8e0c9968
Kaydet (Commit)
8e0c9968
authored
Tem 11, 2010
tarafından
Mark Dickinson
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Issue #9165: Add math.isfinite and cmath.isfinite.
üst
3e742899
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
61 additions
and
0 deletions
+61
-0
cmath.rst
Doc/library/cmath.rst
+6
-0
math.rst
Doc/library/math.rst
+6
-0
test_cmath.py
Lib/test/test_cmath.py
+9
-0
test_math.py
Lib/test/test_math.py
+9
-0
NEWS
Misc/NEWS
+3
-0
cmathmodule.c
Modules/cmathmodule.c
+14
-0
mathmodule.c
Modules/mathmodule.c
+14
-0
No files found.
Doc/library/cmath.rst
Dosyayı görüntüle @
8e0c9968
...
@@ -187,6 +187,12 @@ Hyperbolic functions
...
@@ -187,6 +187,12 @@ Hyperbolic functions
Classification functions
Classification functions
------------------------
------------------------
.. function:: isfinite(x)
Return ``True`` if both the real and imaginary parts of *x* are finite,
and ``False`` otherwise.
.. function:: isinf(x)
.. function:: isinf(x)
Return *True* if the real or the imaginary part of x is positive
Return *True* if the real or the imaginary part of x is positive
...
...
Doc/library/math.rst
Dosyayı görüntüle @
8e0c9968
...
@@ -97,6 +97,12 @@ Number-theoretic and representation functions
...
@@ -97,6 +97,12 @@ Number-theoretic and representation functions
<http://code.activestate.com/recipes/393090/>`_\.
<http://code.activestate.com/recipes/393090/>`_\.
.. function:: isfinite(x)
Return ``True`` if *x* is neither an infinity nor a NaN, and
``False`` otherwise. (Note that ``0.0`` *is* considered finite.)
.. function:: isinf(x)
.. function:: isinf(x)
Check if the float *x* is positive or negative infinity.
Check if the float *x* is positive or negative infinity.
...
...
Lib/test/test_cmath.py
Dosyayı görüntüle @
8e0c9968
...
@@ -442,6 +442,15 @@ class CMathTests(unittest.TestCase):
...
@@ -442,6 +442,15 @@ class CMathTests(unittest.TestCase):
self
.
assertCEqual
(
rect
(
1
,
pi
/
2
),
(
0
,
1.
))
self
.
assertCEqual
(
rect
(
1
,
pi
/
2
),
(
0
,
1.
))
self
.
assertCEqual
(
rect
(
1
,
-
pi
/
2
),
(
0
,
-
1.
))
self
.
assertCEqual
(
rect
(
1
,
-
pi
/
2
),
(
0
,
-
1.
))
def
test_isfinite
(
self
):
real_vals
=
[
float
(
'-inf'
),
-
2.3
,
-
0.0
,
0.0
,
2.3
,
float
(
'inf'
),
float
(
'nan'
)]
for
x
in
real_vals
:
for
y
in
real_vals
:
z
=
complex
(
x
,
y
)
self
.
assertEquals
(
cmath
.
isfinite
(
z
),
math
.
isfinite
(
x
)
and
math
.
isfinite
(
y
))
def
test_isnan
(
self
):
def
test_isnan
(
self
):
self
.
assertFalse
(
cmath
.
isnan
(
1
))
self
.
assertFalse
(
cmath
.
isnan
(
1
))
self
.
assertFalse
(
cmath
.
isnan
(
1
j
))
self
.
assertFalse
(
cmath
.
isnan
(
1
j
))
...
...
Lib/test/test_math.py
Dosyayı görüntüle @
8e0c9968
...
@@ -915,6 +915,15 @@ class MathTests(unittest.TestCase):
...
@@ -915,6 +915,15 @@ class MathTests(unittest.TestCase):
self
.
assertRaises
(
TypeError
,
math
.
trunc
,
1
,
2
)
self
.
assertRaises
(
TypeError
,
math
.
trunc
,
1
,
2
)
self
.
assertRaises
(
TypeError
,
math
.
trunc
,
TestNoTrunc
())
self
.
assertRaises
(
TypeError
,
math
.
trunc
,
TestNoTrunc
())
def
testIsfinite
(
self
):
self
.
assertTrue
(
math
.
isfinite
(
0.0
))
self
.
assertTrue
(
math
.
isfinite
(
-
0.0
))
self
.
assertTrue
(
math
.
isfinite
(
1.0
))
self
.
assertTrue
(
math
.
isfinite
(
-
1.0
))
self
.
assertFalse
(
math
.
isfinite
(
float
(
"nan"
)))
self
.
assertFalse
(
math
.
isfinite
(
float
(
"inf"
)))
self
.
assertFalse
(
math
.
isfinite
(
float
(
"-inf"
)))
def
testIsnan
(
self
):
def
testIsnan
(
self
):
self
.
assertTrue
(
math
.
isnan
(
float
(
"nan"
)))
self
.
assertTrue
(
math
.
isnan
(
float
(
"nan"
)))
self
.
assertTrue
(
math
.
isnan
(
float
(
"inf"
)
*
0.
))
self
.
assertTrue
(
math
.
isnan
(
float
(
"inf"
)
*
0.
))
...
...
Misc/NEWS
Dosyayı görüntüle @
8e0c9968
...
@@ -1415,6 +1415,9 @@ Library
...
@@ -1415,6 +1415,9 @@ Library
Extension Modules
Extension Modules
-----------------
-----------------
- Issue #9165: Add new functions math.isfinite and cmath.isfinite, to
accompany existing isinf and isnan functions.
- Issue #1578269: Implement os.symlink for Windows 6.0+. Patch by
- Issue #1578269: Implement os.symlink for Windows 6.0+. Patch by
Jason R. Coombs
Jason R. Coombs
...
...
Modules/cmathmodule.c
Dosyayı görüntüle @
8e0c9968
...
@@ -1023,6 +1023,19 @@ PyDoc_STRVAR(cmath_rect_doc,
...
@@ -1023,6 +1023,19 @@ PyDoc_STRVAR(cmath_rect_doc,
"rect(r, phi) -> z: complex
\n\n
\
"rect(r, phi) -> z: complex
\n\n
\
Convert from polar coordinates to rectangular coordinates."
);
Convert from polar coordinates to rectangular coordinates."
);
static
PyObject
*
cmath_isfinite
(
PyObject
*
self
,
PyObject
*
args
)
{
Py_complex
z
;
if
(
!
PyArg_ParseTuple
(
args
,
"D:isfinite"
,
&
z
))
return
NULL
;
return
PyBool_FromLong
(
Py_IS_FINITE
(
z
.
real
)
&&
Py_IS_FINITE
(
z
.
imag
));
}
PyDoc_STRVAR
(
cmath_isfinite_doc
,
"isfinite(z) -> bool
\n
\
Return True if both the real and imaginary parts of z are finite, else False."
);
static
PyObject
*
static
PyObject
*
cmath_isnan
(
PyObject
*
self
,
PyObject
*
args
)
cmath_isnan
(
PyObject
*
self
,
PyObject
*
args
)
{
{
...
@@ -1065,6 +1078,7 @@ static PyMethodDef cmath_methods[] = {
...
@@ -1065,6 +1078,7 @@ static PyMethodDef cmath_methods[] = {
{
"cos"
,
cmath_cos
,
METH_VARARGS
,
c_cos_doc
},
{
"cos"
,
cmath_cos
,
METH_VARARGS
,
c_cos_doc
},
{
"cosh"
,
cmath_cosh
,
METH_VARARGS
,
c_cosh_doc
},
{
"cosh"
,
cmath_cosh
,
METH_VARARGS
,
c_cosh_doc
},
{
"exp"
,
cmath_exp
,
METH_VARARGS
,
c_exp_doc
},
{
"exp"
,
cmath_exp
,
METH_VARARGS
,
c_exp_doc
},
{
"isfinite"
,
cmath_isfinite
,
METH_VARARGS
,
cmath_isfinite_doc
},
{
"isinf"
,
cmath_isinf
,
METH_VARARGS
,
cmath_isinf_doc
},
{
"isinf"
,
cmath_isinf
,
METH_VARARGS
,
cmath_isinf_doc
},
{
"isnan"
,
cmath_isnan
,
METH_VARARGS
,
cmath_isnan_doc
},
{
"isnan"
,
cmath_isnan
,
METH_VARARGS
,
cmath_isnan_doc
},
{
"log"
,
cmath_log
,
METH_VARARGS
,
cmath_log_doc
},
{
"log"
,
cmath_log
,
METH_VARARGS
,
cmath_log_doc
},
...
...
Modules/mathmodule.c
Dosyayı görüntüle @
8e0c9968
...
@@ -1817,6 +1817,19 @@ PyDoc_STRVAR(math_radians_doc,
...
@@ -1817,6 +1817,19 @@ PyDoc_STRVAR(math_radians_doc,
"radians(x)
\n\n
\
"radians(x)
\n\n
\
Convert angle x from degrees to radians."
);
Convert angle x from degrees to radians."
);
static
PyObject
*
math_isfinite
(
PyObject
*
self
,
PyObject
*
arg
)
{
double
x
=
PyFloat_AsDouble
(
arg
);
if
(
x
==
-
1
.
0
&&
PyErr_Occurred
())
return
NULL
;
return
PyBool_FromLong
((
long
)
Py_IS_FINITE
(
x
));
}
PyDoc_STRVAR
(
math_isfinite_doc
,
"isfinite(x) -> bool
\n\n
\
Check if float x is finite (not an infinity or NaN)."
);
static
PyObject
*
static
PyObject
*
math_isnan
(
PyObject
*
self
,
PyObject
*
arg
)
math_isnan
(
PyObject
*
self
,
PyObject
*
arg
)
{
{
...
@@ -1868,6 +1881,7 @@ static PyMethodDef math_methods[] = {
...
@@ -1868,6 +1881,7 @@ static PyMethodDef math_methods[] = {
{
"fsum"
,
math_fsum
,
METH_O
,
math_fsum_doc
},
{
"fsum"
,
math_fsum
,
METH_O
,
math_fsum_doc
},
{
"gamma"
,
math_gamma
,
METH_O
,
math_gamma_doc
},
{
"gamma"
,
math_gamma
,
METH_O
,
math_gamma_doc
},
{
"hypot"
,
math_hypot
,
METH_VARARGS
,
math_hypot_doc
},
{
"hypot"
,
math_hypot
,
METH_VARARGS
,
math_hypot_doc
},
{
"isfinite"
,
math_isfinite
,
METH_O
,
math_isfinite_doc
},
{
"isinf"
,
math_isinf
,
METH_O
,
math_isinf_doc
},
{
"isinf"
,
math_isinf
,
METH_O
,
math_isinf_doc
},
{
"isnan"
,
math_isnan
,
METH_O
,
math_isnan_doc
},
{
"isnan"
,
math_isnan
,
METH_O
,
math_isnan_doc
},
{
"ldexp"
,
math_ldexp
,
METH_VARARGS
,
math_ldexp_doc
},
{
"ldexp"
,
math_ldexp
,
METH_VARARGS
,
math_ldexp_doc
},
...
...
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