Skip to content

Commit 31142bb

Browse files
authored
Add complex number support to log1p (#534)
1 parent 74eb089 commit 31142bb

File tree

1 file changed

+31
-5
lines changed

1 file changed

+31
-5
lines changed

spec/API_specification/array_api/elementwise_functions.py

+31-5
Original file line numberDiff line numberDiff line change
@@ -1175,15 +1175,15 @@ def log(x: array, /) -> array:
11751175
"""
11761176

11771177
def log1p(x: array, /) -> array:
1178-
"""
1179-
Calculates an implementation-dependent approximation to ``log(1+x)``, where ``log`` refers to the natural (base ``e``) logarithm, having domain ``[-1, +infinity]`` and codomain ``[-infinity, +infinity]``, for each element ``x_i`` of the input array ``x``.
1178+
r"""
1179+
Calculates an implementation-dependent approximation to ``log(1+x)``, where ``log`` refers to the natural (base ``e``) logarithm, for each element ``x_i`` of the input array ``x``.
11801180
11811181
.. note::
11821182
The purpose of this function is to calculate ``log(1+x)`` more accurately when `x` is close to zero. Accordingly, conforming implementations should avoid implementing this function as simply ``log(1+x)``. See FDLIBM, or some other IEEE 754-2019 compliant mathematical library, for a potential reference implementation.
11831183
11841184
**Special cases**
11851185
1186-
For floating-point operands,
1186+
For real-valued floating-point operands,
11871187
11881188
- If ``x_i`` is ``NaN``, the result is ``NaN``.
11891189
- If ``x_i`` is less than ``-1``, the result is ``NaN``.
@@ -1192,15 +1192,41 @@ def log1p(x: array, /) -> array:
11921192
- If ``x_i`` is ``+0``, the result is ``+0``.
11931193
- If ``x_i`` is ``+infinity``, the result is ``+infinity``.
11941194
1195+
For complex floating-point operands, let ``a = real(x_i)``, ``b = imag(x_i)``, and
1196+
1197+
- If ``a`` is ``-1`` and ``b`` is ``+0``, the result is ``-infinity + 0j``.
1198+
- If ``a`` is a finite number and ``b`` is ``+infinity``, the result is ``+infinity + πj/2``.
1199+
- If ``a`` is a finite number and ``b`` is ``NaN``, the result is ``NaN + NaN j``.
1200+
- If ``a`` is ``-infinity`` and ``b`` is a positive (i.e., greater than ``0``) finite number, the result is ``+infinity + πj``.
1201+
- If ``a`` is ``+infinity`` and ``b`` is a positive (i.e., greater than ``0``) finite number, the result is ``+infinity + 0j``.
1202+
- If ``a`` is ``-infinity`` and ``b`` is ``+infinity``, the result is ``+infinity + 3πj/4``.
1203+
- If ``a`` is ``+infinity`` and ``b`` is ``+infinity``, the result is ``+infinity + πj/4``.
1204+
- If ``a`` is either ``+infinity`` or ``-infinity`` and ``b`` is ``NaN``, the result is ``+infinity + NaN j``.
1205+
- If ``a`` is ``NaN`` and ``b`` is a finite number, the result is ``NaN + NaN j``.
1206+
- If ``a`` is ``NaN`` and ``b`` is ``+infinity``, the result is ``+infinity + NaN j``.
1207+
- If ``a`` is ``NaN`` and ``b`` is ``NaN``, the result is ``NaN + NaN j``.
1208+
1209+
.. note::
1210+
For complex floating-point operands, ``log1p(conj(x))`` must equal ``conj(log1p(x))``.
1211+
1212+
.. note::
1213+
By convention, the branch cut of the natural logarithm is the negative real axis :math:`(-\infty, 0)`.
1214+
1215+
The natural logarithm is a continuous function from above the branch cut, taking into account the sign of the imaginary component.
1216+
1217+
Accordingly, for complex arguments, the function returns the natural logarithm in the range of a strip in the interval :math:`[-\pi j, +\pi j]` along the imaginary axis and mathematically unbounded along the real axis.
1218+
1219+
*Note: branch cuts have provisional status* (see :ref:`branch-cuts`).
1220+
11951221
Parameters
11961222
----------
11971223
x: array
1198-
input array. Should have a real-valued floating-point data type.
1224+
input array. Should have a floating-point data type.
11991225
12001226
Returns
12011227
-------
12021228
out: array
1203-
an array containing the evaluated result for each element in ``x``. The returned array must have a real-valued floating-point data type determined by :ref:`type-promotion`.
1229+
an array containing the evaluated result for each element in ``x``. The returned array must have a floating-point data type determined by :ref:`type-promotion`.
12041230
"""
12051231

12061232
def log2(x: array, /) -> array:

0 commit comments

Comments
 (0)