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
e119b3d1
Unverified
Kaydet (Commit)
e119b3d1
authored
Haz 08, 2019
tarafından
Raymond Hettinger
Kaydeden (comit)
GitHub
Haz 08, 2019
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
bpo-37178: Allow a one argument form of math.perm() (GH-13905)
üst
8cc605ac
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
34 additions
and
9 deletions
+34
-9
math.rst
Doc/library/math.rst
+4
-1
test_math.py
Lib/test/test_math.py
+7
-2
2019-06-07-17-11-34.bpo-37178.b1StSv.rst
...S.d/next/Library/2019-06-07-17-11-34.bpo-37178.b1StSv.rst
+2
-0
2019-06-07-17-16-09.bpo-37178.Day_oB.rst
...S.d/next/Library/2019-06-07-17-16-09.bpo-37178.Day_oB.rst
+2
-0
mathmodule.c.h
Modules/clinic/mathmodule.c.h
+11
-4
mathmodule.c
Modules/mathmodule.c
+8
-2
No files found.
Doc/library/math.rst
Dosyayı görüntüle @
e119b3d1
...
...
@@ -210,7 +210,7 @@ Number-theoretic and representation functions
of *x* and are floats.
.. function:: perm(n, k)
.. function:: perm(n, k
=None
)
Return the number of ways to choose *k* items from *n* items
without repetition and with order.
...
...
@@ -218,6 +218,9 @@ Number-theoretic and representation functions
Evaluates to ``n! / (n - k)!`` when ``k <= n`` and evaluates
to zero when ``k > n``.
If *k* is not specified or is None, then *k* defaults to *n*
and the function returns ``n!``.
Raises :exc:`TypeError` if either of the arguments are not integers.
Raises :exc:`ValueError` if either of the arguments are negative.
...
...
Lib/test/test_math.py
Dosyayı görüntüle @
e119b3d1
...
...
@@ -1885,8 +1885,13 @@ class IsCloseTests(unittest.TestCase):
self
.
assertEqual
(
perm
(
n
,
1
),
n
)
self
.
assertEqual
(
perm
(
n
,
n
),
factorial
(
n
))
# Test one argument form
for
n
in
range
(
20
):
self
.
assertEqual
(
perm
(
n
),
factorial
(
n
))
self
.
assertEqual
(
perm
(
n
,
None
),
factorial
(
n
))
# Raises TypeError if any argument is non-integer or argument count is
# not 2
# not
1 or
2
self
.
assertRaises
(
TypeError
,
perm
,
10
,
1.0
)
self
.
assertRaises
(
TypeError
,
perm
,
10
,
decimal
.
Decimal
(
1.0
))
self
.
assertRaises
(
TypeError
,
perm
,
10
,
"1"
)
...
...
@@ -1894,7 +1899,7 @@ class IsCloseTests(unittest.TestCase):
self
.
assertRaises
(
TypeError
,
perm
,
decimal
.
Decimal
(
10.0
),
1
)
self
.
assertRaises
(
TypeError
,
perm
,
"10"
,
1
)
self
.
assertRaises
(
TypeError
,
perm
,
10
)
self
.
assertRaises
(
TypeError
,
perm
)
self
.
assertRaises
(
TypeError
,
perm
,
10
,
1
,
3
)
self
.
assertRaises
(
TypeError
,
perm
)
...
...
Misc/NEWS.d/next/Library/2019-06-07-17-11-34.bpo-37178.b1StSv.rst
0 → 100644
Dosyayı görüntüle @
e119b3d1
For math.perm(n, k), let k default to n, giving the same result as
factorial.
Misc/NEWS.d/next/Library/2019-06-07-17-16-09.bpo-37178.Day_oB.rst
0 → 100644
Dosyayı görüntüle @
e119b3d1
Give math.perm() a one argument form that means the same as
math.factorial().
Modules/clinic/mathmodule.c.h
Dosyayı görüntüle @
e119b3d1
...
...
@@ -639,7 +639,7 @@ exit:
}
PyDoc_STRVAR
(
math_perm__doc__
,
"perm($module, n, k, /)
\n
"
"perm($module, n, k
=None
, /)
\n
"
"--
\n
"
"
\n
"
"Number of ways to choose k items from n items without repetition and with order.
\n
"
...
...
@@ -647,6 +647,9 @@ PyDoc_STRVAR(math_perm__doc__,
"Evaluates to n! / (n - k)! when k <= n and evaluates
\n
"
"to zero when k > n.
\n
"
"
\n
"
"If k is not specified or is None, then k defaults to n
\n
"
"and the function returns n!.
\n
"
"
\n
"
"Raises TypeError if either of the arguments are not integers.
\n
"
"Raises ValueError if either of the arguments are negative."
);
...
...
@@ -661,13 +664,17 @@ math_perm(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
{
PyObject
*
return_value
=
NULL
;
PyObject
*
n
;
PyObject
*
k
;
PyObject
*
k
=
Py_None
;
if
(
!
_PyArg_CheckPositional
(
"perm"
,
nargs
,
2
,
2
))
{
if
(
!
_PyArg_CheckPositional
(
"perm"
,
nargs
,
1
,
2
))
{
goto
exit
;
}
n
=
args
[
0
];
if
(
nargs
<
2
)
{
goto
skip_optional
;
}
k
=
args
[
1
];
skip_optional:
return_value
=
math_perm_impl
(
module
,
n
,
k
);
exit:
...
...
@@ -713,4 +720,4 @@ math_comb(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
exit:
return
return_value
;
}
/*[clinic end generated code: output=
5004266613284dcc
input=a9049054013a1b77]*/
/*[clinic end generated code: output=
0eb1e76a769cdd30
input=a9049054013a1b77]*/
Modules/mathmodule.c
Dosyayı görüntüle @
e119b3d1
...
...
@@ -3002,7 +3002,7 @@ math_prod_impl(PyObject *module, PyObject *iterable, PyObject *start)
math.perm
n: object
k: object
k: object
= None
/
Number of ways to choose k items from n items without repetition and with order.
...
...
@@ -3010,18 +3010,24 @@ Number of ways to choose k items from n items without repetition and with order.
Evaluates to n! / (n - k)! when k <= n and evaluates
to zero when k > n.
If k is not specified or is None, then k defaults to n
and the function returns n!.
Raises TypeError if either of the arguments are not integers.
Raises ValueError if either of the arguments are negative.
[clinic start generated code]*/
static
PyObject
*
math_perm_impl
(
PyObject
*
module
,
PyObject
*
n
,
PyObject
*
k
)
/*[clinic end generated code: output=e021a25469653e23 input=
b2e7729d9a1949cf
]*/
/*[clinic end generated code: output=e021a25469653e23 input=
5311c5a00f359b53
]*/
{
PyObject
*
result
=
NULL
,
*
factor
=
NULL
;
int
overflow
,
cmp
;
long
long
i
,
factors
;
if
(
k
==
Py_None
)
{
return
math_factorial
(
module
,
n
);
}
n
=
PyNumber_Index
(
n
);
if
(
n
==
NULL
)
{
return
NULL
;
...
...
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