Skip to content

Commit ea8f6a9

Browse files
authored
Add complex number support to expm1 (#452)
* Add complex number support to `expm1` * Update copy * Add note concerning complex conjugation * Specify special cases in terms of `cis` function * Fix special cases and move note * Move note * Move note
1 parent aefec14 commit ea8f6a9

File tree

1 file changed

+31
-7
lines changed

1 file changed

+31
-7
lines changed

spec/API_specification/array_api/elementwise_functions.py

Lines changed: 31 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -607,9 +607,6 @@ def exp(x: array, /) -> array:
607607
608608
For complex floating-point operands, let ``a = real(x_i)``, ``b = imag(x_i)``, and
609609
610-
.. note::
611-
For complex floating-point operands, ``exp(conj(x))`` must equal ``conj(exp(x))``.
612-
613610
- If ``a`` is either ``+0`` or ``-0`` and ``b`` is ``+0``, the result is ``1 + 0j``.
614611
- If ``a`` is a finite number and ``b`` is ``+infinity``, the result is ``NaN + NaN j``.
615612
- If ``a`` is a finite number and ``b`` is ``NaN``, the result is ``NaN + NaN j``.
@@ -626,6 +623,9 @@ def exp(x: array, /) -> array:
626623
627624
where ``cis(v)`` is ``cos(v) + sin(v)*1j``.
628625
626+
.. note::
627+
For complex floating-point operands, ``exp(conj(x))`` must equal ``conj(exp(x))``.
628+
629629
.. note::
630630
The exponential function is an entire function in the complex plane and has no branch cuts.
631631
@@ -642,30 +642,54 @@ def exp(x: array, /) -> array:
642642

643643
def expm1(x: array, /) -> array:
644644
"""
645-
Calculates an implementation-dependent approximation to ``exp(x)-1``, having domain ``[-infinity, +infinity]`` and codomain ``[-1, +infinity]``, for each element ``x_i`` of the input array ``x``.
645+
Calculates an implementation-dependent approximation to ``exp(x)-1`` for each element ``x_i`` of the input array ``x``.
646646
647647
.. note::
648648
The purpose of this function is to calculate ``exp(x)-1.0`` more accurately when `x` is close to zero. Accordingly, conforming implementations should avoid implementing this function as simply ``exp(x)-1.0``. See FDLIBM, or some other IEEE 754-2019 compliant mathematical library, for a potential reference implementation.
649649
650650
**Special cases**
651651
652-
For floating-point operands,
652+
For real-valued floating-point operands,
653653
654654
- If ``x_i`` is ``NaN``, the result is ``NaN``.
655655
- If ``x_i`` is ``+0``, the result is ``+0``.
656656
- If ``x_i`` is ``-0``, the result is ``-0``.
657657
- If ``x_i`` is ``+infinity``, the result is ``+infinity``.
658658
- If ``x_i`` is ``-infinity``, the result is ``-1``.
659659
660+
For complex floating-point operands, let ``a = real(x_i)``, ``b = imag(x_i)``, and
661+
662+
- If ``a`` is either ``+0`` or ``-0`` and ``b`` is ``+0``, the result is ``0 + 0j``.
663+
- If ``a`` is a finite number and ``b`` is ``+infinity``, the result is ``NaN + NaN j``.
664+
- If ``a`` is a finite number and ``b`` is ``NaN``, the result is ``NaN + NaN j``.
665+
- If ``a`` is ``+infinity`` and ``b`` is ``+0``, the result is ``+infinity + 0j``.
666+
- If ``a`` is ``-infinity`` and ``b`` is a finite number, the result is ``+0 * cis(b) - 1.0``.
667+
- If ``a`` is ``+infinity`` and ``b`` is a nonzero finite number, the result is ``+infinity * cis(b) - 1.0``.
668+
- If ``a`` is ``-infinity`` and ``b`` is ``+infinity``, the result is ``-1 + 0j`` (sign of imaginary component is unspecified).
669+
- If ``a`` is ``+infinity`` and ``b`` is ``+infinity``, the result is ``infinity + NaN j`` (sign of real component is unspecified).
670+
- If ``a`` is ``-infinity`` and ``b`` is ``NaN``, the result is ``-1 + 0j`` (sign of imaginary component is unspecified).
671+
- If ``a`` is ``+infinity`` and ``b`` is ``NaN``, the result is ``infinity + NaN j`` (sign of real component is unspecified).
672+
- If ``a`` is ``NaN`` and ``b`` is ``+0``, the result is ``NaN + 0j``.
673+
- If ``a`` is ``NaN`` and ``b`` is not equal to ``0``, the result is ``NaN + NaN j``.
674+
- If ``a`` is ``NaN`` and ``b`` is ``NaN``, the result is ``NaN + NaN j``.
675+
676+
where ``cis(v)`` is ``cos(v) + sin(v)*1j``.
677+
678+
.. note::
679+
For complex floating-point operands, ``expm1(conj(x))`` must equal ``conj(expm1(x))``.
680+
681+
.. note::
682+
The exponential function is an entire function in the complex plane and has no branch cuts.
683+
660684
Parameters
661685
----------
662686
x: array
663-
input array. Should have a real-valued floating-point data type.
687+
input array. Should have a floating-point data type.
664688
665689
Returns
666690
-------
667691
out: array
668-
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`.
692+
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`.
669693
"""
670694

671695
def floor(x: array, /) -> array:

0 commit comments

Comments
 (0)