-
-
Notifications
You must be signed in to change notification settings - Fork 30.3k
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
gh-126061: Add PyLong_IsPositive/Zero/Negative() functions #126065
base: main
Are you sure you want to change the base?
Changes from 6 commits
207a24f
6bbb376
7436752
1460879
b6a9126
71bf57b
04b23c7
a30a7f1
b2f3762
a18781f
c50d7a2
63adaf6
5ec2379
196cf36
73e150d
630bc01
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. | ||||||
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. If you dislike strictly, I suggest:
Suggested change
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. 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." |
||||||
On success, return 1 if *obj* is positive, and 0 otherwise. | ||||||
On failure, return -1 with an exception set. This function always succeeds | ||||||
if *obj* is a :c:type:`PyLongObject` or its subtype. | ||||||
erlend-aasland marked this conversation as resolved.
Show resolved
Hide resolved
rruuaanng marked this conversation as resolved.
Show resolved
Hide resolved
rruuaanng marked this conversation as resolved.
Show resolved
Hide resolved
rruuaanng marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
.. versionadded:: next | ||||||
.. c:function:: int PyLong_IsNegative(PyObject *obj) | ||||||
Check if the integer object *obj* is negative. | ||||||
On success, return 1 if *obj* is negative, and 0 otherwise. | ||||||
On failure, return -1 with an exception set. This function always succeeds | ||||||
if *obj* is a :c:type:`PyLongObject` or its subtype. | ||||||
.. versionadded:: next | ||||||
.. c:function:: int PyLong_IsZero(PyObject *obj) | ||||||
Check if the integer object *obj* is zero. | ||||||
On success, return 1 if *obj* is zero, and 0 if it is non-zero. | ||||||
On failure, return -1 with an exception set. This function always succeeds | ||||||
if *obj* is a :c:type:`PyLongObject` or its subtype. | ||||||
.. versionadded:: next | ||||||
.. c:function:: PyObject* PyLong_GetInfo(void) | ||||||
On success, return a read only :term:`named tuple`, that holds | ||||||
|
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.
Show resolved
Hide resolved
|
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.
Maybe add:
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 think there is no ambiguity. Positive is for, well, being strictly positive. Else we would use something like "nonnegative".
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.
For me, zero is a positive number. "strictly positive" is used in a few places in Python:
An alternative is to say "Check if the integer is 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.
Uh, it doubt I'm able to find math source with this meaning. But a lot for a different opinion:
https://mathworld.wolfram.com/PositiveInteger.html
https://mathworld.wolfram.com/PositiveNumber.html
https://en.wikipedia.org/wiki/Integer
and
There is another story: whether
0
is a natural number or not.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've applied this advice to positive and negative. Maybe that's more appropriate. Maybe
victor
meant it more purely (it's very positive💯).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.
Also it's very negative:D
Lets just stick with math terminolgy.
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.
@rruuaanng, please don't mark unresolved conversations as resolved.