-
-
Notifications
You must be signed in to change notification settings - Fork 35.3k
doc: Improve C API manual for complex number objects #156914
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
base: main
Are you sure you want to change the base?
Changes from all commits
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 | ||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -57,7 +57,7 @@ Complex Number Objects | |||||||||||
| not defined then it falls back to call :c:func:`PyFloat_AsDouble` and | ||||||||||||
| returns its result. | ||||||||||||
|
|
||||||||||||
| Upon failure, this method returns ``-1.0`` with an exception set, so one | ||||||||||||
| Upon failure, this function returns ``-1.0`` with an exception set, so one | ||||||||||||
| should call :c:func:`PyErr_Occurred` to check for errors. | ||||||||||||
|
|
||||||||||||
| .. versionchanged:: 3.13 | ||||||||||||
|
|
@@ -73,7 +73,7 @@ Complex Number Objects | |||||||||||
| not defined then it falls back to call :c:func:`PyFloat_AsDouble` and | ||||||||||||
| returns ``0.0`` on success. | ||||||||||||
|
|
||||||||||||
| Upon failure, this method returns ``-1.0`` with an exception set, so one | ||||||||||||
| Upon failure, this function returns ``-1.0`` with an exception set, so one | ||||||||||||
| should call :c:func:`PyErr_Occurred` to check for errors. | ||||||||||||
|
|
||||||||||||
| .. versionchanged:: 3.13 | ||||||||||||
|
|
@@ -112,7 +112,7 @@ Complex Number Objects | |||||||||||
| :meth:`~object.__float__`. If :meth:`!__float__` is not defined then it falls back | ||||||||||||
| to :meth:`~object.__index__`. | ||||||||||||
|
|
||||||||||||
| Upon failure, this method returns :c:type:`Py_complex` | ||||||||||||
| Upon failure, this function returns :c:type:`Py_complex` | ||||||||||||
| with :c:member:`~Py_complex.real` set to ``-1.0`` and with an exception set, so one | ||||||||||||
| should call :c:func:`PyErr_Occurred` to check for errors. | ||||||||||||
|
|
||||||||||||
|
|
@@ -171,7 +171,7 @@ the :ref:`Number Protocol <number>` API or use native complex types, like | |||||||||||
| Return the quotient of two complex numbers, using the C :c:type:`Py_complex` | ||||||||||||
| representation. | ||||||||||||
|
|
||||||||||||
| If *divisor* is null, this method returns zero and sets | ||||||||||||
| If *divisor* is zero, this function returns zero and sets | ||||||||||||
| :c:data:`errno` to :c:macro:`!EDOM`. | ||||||||||||
|
|
||||||||||||
| .. deprecated:: 3.15 | ||||||||||||
|
|
@@ -182,10 +182,11 @@ the :ref:`Number Protocol <number>` API or use native complex types, like | |||||||||||
| Return the exponentiation of *num* by *exp*, using the C :c:type:`Py_complex` | ||||||||||||
| representation. | ||||||||||||
|
|
||||||||||||
| If *num* is null and *exp* is not a positive real number, | ||||||||||||
| this method returns zero and sets :c:data:`errno` to :c:macro:`!EDOM`. | ||||||||||||
| If *exp* is zero, this function returns ``{1.0, 0.0}``; otherwise | ||||||||||||
| if *num* is zero and *exp* is not a positive real number, | ||||||||||||
| this function returns zero and sets :c:data:`errno` to :c:macro:`!EDOM`. | ||||||||||||
|
skirpichev marked this conversation as resolved.
Comment on lines
+185
to
+187
Member
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
Contributor
Author
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 think it's good to document the return value in this case because I do not think it's documented in the C standard. MPC, Python, GNU libc, Intel libm, FreeBSD-15 all do as I've written in this PR. (Older versions of FreeBSD did not, but it was changed when my colleague reported it to them.) I think AMD's libm returns (0, 0). Numeric Types footnote 5 states:
It's not something we'd want to change in the future. The phrase "not nonnegative" is awkward. I prefer my wording.
Member
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.
Then perhaps it's a good reason to not document this? We also have a lot of other corner cases for complex numbers with special components: #60200 (comment) But anyway, we don't develop deprecated stuff, that includes soft-deprecated API like
Well, then up to other reviewers. It's precise, there is no double negation, if you are about. |
||||||||||||
|
|
||||||||||||
| Set :c:data:`errno` to :c:macro:`!ERANGE` on overflows. | ||||||||||||
| On overflow, this function sets :c:data:`errno` to :c:macro:`!ERANGE`. | ||||||||||||
|
Member
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 think that old sentence was wrong or grammatically invalid. Lets keep it as is.
Contributor
Author
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. The old sentence is imperative. It's giving an order to the reader to do something. But, it's not intended for the reader to set anything. It's the function that sets errno. The sentence above is already correct. The mismatch between the two is jarring to a native English speaker. Let's make the change.
Member
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.
Ok, up to other reviewers. This still looks as a code churn for me. And, perhaps, this open a Pandora box... Look on PyLong_AsInt64():
|
||||||||||||
|
|
||||||||||||
| .. deprecated:: 3.15 | ||||||||||||
|
|
||||||||||||
|
|
@@ -194,6 +195,6 @@ the :ref:`Number Protocol <number>` API or use native complex types, like | |||||||||||
|
|
||||||||||||
| Return the absolute value of the complex number *num*. | ||||||||||||
|
|
||||||||||||
| Set :c:data:`errno` to :c:macro:`!ERANGE` on overflows. | ||||||||||||
| On overflow, this function sets :c:data:`errno` to :c:macro:`!ERANGE`. | ||||||||||||
|
Member
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. Same here.
Contributor
Author
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. Same as above. |
||||||||||||
|
|
||||||||||||
| .. deprecated:: 3.15 | ||||||||||||
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.
Do you prefer the following suggestion?