Skip to content

Commit 931144e

Browse files
committed
Fix duplicate content and missing special cases
1 parent 6789626 commit 931144e

File tree

1 file changed

+12
-36
lines changed

1 file changed

+12
-36
lines changed

spec/API_specification/array_api/elementwise_functions.py

Lines changed: 12 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -407,6 +407,18 @@ def atan(x: array, /) -> array:
407407
408408
Notes
409409
-----
410+
411+
**Special cases**
412+
413+
For real-valued floating-point operands,
414+
415+
- If ``x_i`` is ``NaN``, the result is ``NaN``.
416+
- If ``x_i`` is ``+0``, the result is ``+0``.
417+
- If ``x_i`` is ``-0``, the result is ``-0``.
418+
- If ``x_i`` is ``+infinity``, the result is an implementation-dependent approximation to ``+π/2``.
419+
- If ``x_i`` is ``-infinity``, the result is an implementation-dependent approximation to ``-π/2``.
420+
421+
For complex floating-point operands, special cases must be handled as if the operation is implemented as ``-1j * atanh(x*1j)``.
410422
"""
411423

412424

@@ -1072,42 +1084,6 @@ def floor_divide(x1: array, x2: array, /) -> array:
10721084
.. note::
10731085
For input arrays which promote to an integer data type, the result of division by zero is unspecified and thus implementation-defined.
10741086
1075-
**Special cases**
1076-
1077-
.. note::
1078-
Floor division was introduced in Python via `PEP 238 <https://www.python.org/dev/peps/pep-0238/>`_ with the goal to disambiguate "true division" (i.e., computing an approximation to the mathematical operation of division) from "floor division" (i.e., rounding the result of division toward negative infinity). The former was computed when one of the operands was a ``float``, while the latter was computed when both operands were ``int``\s. Overloading the ``/`` operator to support both behaviors led to subtle numerical bugs when integers are possible, but not expected.
1079-
1080-
To resolve this ambiguity, ``/`` was designated for true division, and ``//`` was designated for floor division. Semantically, floor division was `defined <https://www.python.org/dev/peps/pep-0238/#semantics-of-floor-division>`_ as equivalent to ``a // b == floor(a/b)``; however, special floating-point cases were left ill-defined.
1081-
1082-
Accordingly, floor division is not implemented consistently across array libraries for some of the special cases documented below. Namely, when one of the operands is ``infinity``, libraries may diverge with some choosing to strictly follow ``floor(a/b)`` and others choosing to pair ``//`` with ``%`` according to the relation ``b = a % b + b * (a // b)``. The special cases leading to divergent behavior are documented below.
1083-
1084-
This specification prefers floor division to match ``floor(divide(x1, x2))`` in order to avoid surprising and unexpected results; however, array libraries may choose to more strictly follow Python behavior.
1085-
1086-
For floating-point operands,
1087-
1088-
- If either ``x1_i`` or ``x2_i`` is ``NaN``, the result is ``NaN``.
1089-
- If ``x1_i`` is either ``+infinity`` or ``-infinity`` and ``x2_i`` is either ``+infinity`` or ``-infinity``, the result is ``NaN``.
1090-
- If ``x1_i`` is either ``+0`` or ``-0`` and ``x2_i`` is either ``+0`` or ``-0``, the result is ``NaN``.
1091-
- If ``x1_i`` is ``+0`` and ``x2_i`` is greater than ``0``, the result is ``+0``.
1092-
- If ``x1_i`` is ``-0`` and ``x2_i`` is greater than ``0``, the result is ``-0``.
1093-
- If ``x1_i`` is ``+0`` and ``x2_i`` is less than ``0``, the result is ``-0``.
1094-
- If ``x1_i`` is ``-0`` and ``x2_i`` is less than ``0``, the result is ``+0``.
1095-
- If ``x1_i`` is greater than ``0`` and ``x2_i`` is ``+0``, the result is ``+infinity``.
1096-
- If ``x1_i`` is greater than ``0`` and ``x2_i`` is ``-0``, the result is ``-infinity``.
1097-
- If ``x1_i`` is less than ``0`` and ``x2_i`` is ``+0``, the result is ``-infinity``.
1098-
- If ``x1_i`` is less than ``0`` and ``x2_i`` is ``-0``, the result is ``+infinity``.
1099-
- If ``x1_i`` is ``+infinity`` and ``x2_i`` is a positive (i.e., greater than ``0``) finite number, the result is ``+infinity``. (**note**: libraries may return ``NaN`` to match Python behavior.)
1100-
- If ``x1_i`` is ``+infinity`` and ``x2_i`` is a negative (i.e., less than ``0``) finite number, the result is ``-infinity``. (**note**: libraries may return ``NaN`` to match Python behavior.)
1101-
- If ``x1_i`` is ``-infinity`` and ``x2_i`` is a positive (i.e., greater than ``0``) finite number, the result is ``-infinity``. (**note**: libraries may return ``NaN`` to match Python behavior.)
1102-
- If ``x1_i`` is ``-infinity`` and ``x2_i`` is a negative (i.e., less than ``0``) finite number, the result is ``+infinity``. (**note**: libraries may return ``NaN`` to match Python behavior.)
1103-
- If ``x1_i`` is a positive (i.e., greater than ``0``) finite number and ``x2_i`` is ``+infinity``, the result is ``+0``.
1104-
- If ``x1_i`` is a positive (i.e., greater than ``0``) finite number and ``x2_i`` is ``-infinity``, the result is ``-0``. (**note**: libraries may return ``-1.0`` to match Python behavior.)
1105-
- If ``x1_i`` is a negative (i.e., less than ``0``) finite number and ``x2_i`` is ``+infinity``, the result is ``-0``. (**note**: libraries may return ``-1.0`` to match Python behavior.)
1106-
- If ``x1_i`` is a negative (i.e., less than ``0``) finite number and ``x2_i`` is ``-infinity``, the result is ``+0``.
1107-
- If ``x1_i`` and ``x2_i`` have the same mathematical sign and are both nonzero finite numbers, the result has a positive mathematical sign.
1108-
- If ``x1_i`` and ``x2_i`` have different mathematical signs and are both nonzero finite numbers, the result has a negative mathematical sign.
1109-
- In the remaining cases, where neither ``-infinity``, ``+0``, ``-0``, nor ``NaN`` is involved, the quotient must be computed and rounded to the greatest (i.e., closest to `+infinity`) representable integer-value number that is not greater than the division result. If the magnitude is too large to represent, the operation overflows and the result is an ``infinity`` of appropriate mathematical sign. If the magnitude is too small to represent, the operation underflows and the result is a zero of appropriate mathematical sign.
1110-
11111087
Parameters
11121088
----------
11131089
x1: array

0 commit comments

Comments
 (0)