Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
45e0411e
Commit
45e0411e
authored
Jun 16, 2019
by
Mark Dickinson
Committed by
GitHub
Jun 16, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Simplify negativity checks in math.comb and math.perm. (GH-13870)
parent
55295156
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
16 additions
and
10 deletions
+16
-10
Modules/mathmodule.c
Modules/mathmodule.c
+16
-10
No files found.
Modules/mathmodule.c
View file @
45e0411e
...
...
@@ -3056,6 +3056,12 @@ math_perm_impl(PyObject *module, PyObject *n, PyObject *k)
"n must be a non-negative integer"
);
goto
error
;
}
if
(
Py_SIZE
(
k
)
<
0
)
{
PyErr_SetString
(
PyExc_ValueError
,
"k must be a non-negative integer"
);
goto
error
;
}
cmp
=
PyObject_RichCompareBool
(
n
,
k
,
Py_LT
);
if
(
cmp
!=
0
)
{
if
(
cmp
>
0
)
{
...
...
@@ -3072,11 +3078,8 @@ math_perm_impl(PyObject *module, PyObject *n, PyObject *k)
LLONG_MAX
);
goto
error
;
}
else
if
(
overflow
<
0
||
factors
<
0
)
{
if
(
!
PyErr_Occurred
())
{
PyErr_SetString
(
PyExc_ValueError
,
"k must be a non-negative integer"
);
}
else
if
(
factors
==
-
1
)
{
/* k is nonnegative, so a return value of -1 can only indicate error */
goto
error
;
}
...
...
@@ -3176,6 +3179,12 @@ math_comb_impl(PyObject *module, PyObject *n, PyObject *k)
"n must be a non-negative integer"
);
goto
error
;
}
if
(
Py_SIZE
(
k
)
<
0
)
{
PyErr_SetString
(
PyExc_ValueError
,
"k must be a non-negative integer"
);
goto
error
;
}
/* k = min(k, n - k) */
temp
=
PyNumber_Subtract
(
n
,
k
);
if
(
temp
==
NULL
)
{
...
...
@@ -3204,11 +3213,8 @@ math_comb_impl(PyObject *module, PyObject *n, PyObject *k)
LLONG_MAX
);
goto
error
;
}
else
if
(
overflow
<
0
||
factors
<
0
)
{
if
(
!
PyErr_Occurred
())
{
PyErr_SetString
(
PyExc_ValueError
,
"k must be a non-negative integer"
);
}
if
(
factors
==
-
1
)
{
/* k is nonnegative, so a return value of -1 can only indicate error */
goto
error
;
}
...
...
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