-
-
Notifications
You must be signed in to change notification settings - Fork 33.2k
gh-126061: Add PyLong_IsPositive/Zero/Negative() functions #126065
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
207a24f
6bbb376
7436752
1460879
b6a9126
71bf57b
04b23c7
a30a7f1
b2f3762
a18781f
c50d7a2
63adaf6
5ec2379
196cf36
73e150d
630bc01
daecbc9
b1b82ff
5e7e6ce
43cfbb4
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -571,6 +571,42 @@ distinguished from a number. Use :c:func:`PyErr_Occurred` to disambiguate. | |||||
| .. versionadded:: 3.14 | ||||||
|
|
||||||
|
|
||||||
| .. c:function:: int PyLong_IsPositive(PyObject *obj) | ||||||
|
|
||||||
| Check if the integer object *obj* is positive. | ||||||
|
||||||
| Check if the integer object *obj* is positive. | |
| Check if the integer object *obj* is positive: greater than zero. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't feel this addition is needed.
But at least this form is less confusing than "strictly positive". Maybe: "Check if the integer object obj is positive, i.e. greater than zero."
erlend-aasland marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
rruuaanng marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
rruuaanng marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
rruuaanng marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
skirpichev marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
skirpichev marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
skirpichev marked this conversation as resolved.
Show resolved
Hide resolved
skirpichev marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| Add :c:func:`PyLong_IsPositive`, :c:func:`PyLong_IsNegative` | ||
| and :c:func:`PyLong_IsZero` for checking if :c:type:`PyLongObject` | ||
| is positive, negative, or zero. | ||
rruuaanng marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| Original file line number | Diff line number | Diff line change | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -769,6 +769,36 @@ PyLong_AsUnsignedLongMask(PyObject *op) | |||||||||||||
| return val; | ||||||||||||||
| } | ||||||||||||||
|
|
||||||||||||||
| int | ||||||||||||||
| PyLong_IsPositive(PyObject *obj) | ||||||||||||||
| { | ||||||||||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||
| if (!PyLong_Check(obj)) { | ||||||||||||||
| PyErr_Format(PyExc_TypeError, "expect int, got %T", obj); | ||||||||||||||
erlend-aasland marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
rruuaanng marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||||||||||||||
| return -1; | ||||||||||||||
| } | ||||||||||||||
| return _PyLong_IsPositive((PyLongObject *)obj); | ||||||||||||||
| } | ||||||||||||||
|
|
||||||||||||||
| int | ||||||||||||||
| PyLong_IsNegative(PyObject *obj) | ||||||||||||||
| { | ||||||||||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||
| if (!PyLong_Check(obj)) { | ||||||||||||||
| PyErr_Format(PyExc_TypeError, "expect int, got %T", obj); | ||||||||||||||
erlend-aasland marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
rruuaanng marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||||||||||||||
| return -1; | ||||||||||||||
| } | ||||||||||||||
| return _PyLong_IsNegative((PyLongObject *)obj); | ||||||||||||||
| } | ||||||||||||||
|
|
||||||||||||||
| int | ||||||||||||||
| PyLong_IsZero(PyObject *obj) | ||||||||||||||
| { | ||||||||||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||
| if (!PyLong_Check(obj)) { | ||||||||||||||
| PyErr_Format(PyExc_TypeError, "expect int, got %T", obj); | ||||||||||||||
erlend-aasland marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
rruuaanng marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||||||||||||||
| return -1; | ||||||||||||||
| } | ||||||||||||||
| return _PyLong_IsZero((PyLongObject *)obj); | ||||||||||||||
| } | ||||||||||||||
|
|
||||||||||||||
| int | ||||||||||||||
| _PyLong_Sign(PyObject *vv) | ||||||||||||||
| { | ||||||||||||||
|
|
||||||||||||||
Uh oh!
There was an error while loading. Please reload this page.