Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 9 additions & 8 deletions Doc/c-api/complex.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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.

Expand Down Expand Up @@ -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
Expand All @@ -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

Copy link
Copy Markdown
Contributor Author

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?

Suggested change
If *exp* is zero, this function returns ``{1.0, 0.0}``; otherwise
If *num* is zero and *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`.
Comment thread
skirpichev marked this conversation as resolved.
Comment on lines +185 to +187

@skirpichev skirpichev Sep 4, 2026

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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`.
If *num* is zero and *exp* is not a nonnegative real number,
this function returns zero and sets :c:data:`errno` to :c:macro:`!EDOM`.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The 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:

Python defines pow(0, 0) and 0 ** 0 to be 1, as is common for programming languages.

It's not something we'd want to change in the future.

The phrase "not nonnegative" is awkward. I prefer my wording.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I do not think it's documented in the C standard.

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 _Py_c_pow().

The phrase "not nonnegative" is awkward.

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`.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The 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.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The 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.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The 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.

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():

Set *value and return 0 on success. Set an exception and return -1 on error.


.. deprecated:: 3.15

Expand All @@ -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`.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as above.


.. deprecated:: 3.15
Loading