@@ -1766,19 +1766,38 @@ def round(x: array, /) -> array:
1766
1766
"""
1767
1767
1768
1768
def sign (x : array , / ) -> array :
1769
- """
1769
+ r """
1770
1770
Returns an indication of the sign of a number for each element ``x_i`` of the input array ``x``.
1771
1771
1772
+ The sign function (also known as the **signum function**) of a number :math:`x_i` is defined as
1773
+
1774
+ .. math::
1775
+ \operatorname{sign}(x_i) = \begin{cases}
1776
+ 0 & \textrm{if } x_i = 0 \\
1777
+ \frac{x}{|x|} & \textrm{otherwise}
1778
+ \end{cases}
1779
+
1780
+ where :math:`|x_i|` is the absolute value of :math:`x_i`.
1781
+
1772
1782
**Special cases**
1773
1783
1784
+ For real-valued operands,
1785
+
1774
1786
- If ``x_i`` is less than ``0``, the result is ``-1``.
1775
1787
- If ``x_i`` is either ``-0`` or ``+0``, the result is ``0``.
1776
1788
- If ``x_i`` is greater than ``0``, the result is ``+1``.
1789
+ - If ``x_i`` is ``NaN``, the result is ``NaN``.
1790
+
1791
+ For complex floating-point operands, let ``a = real(x_i)``, ``b = imag(x_i)``, and
1792
+
1793
+ - If ``a`` is either ``-0`` or ``+0`` and ``b`` is either ``-0`` or ``+0``, the result is ``0 + 0j``.
1794
+ - If ``a`` is ``NaN`` or ``b`` is ``NaN``, the result is ``NaN + NaN j``.
1795
+ - In the remaining cases, special cases must be handled according to the rules of complex number division (see :func:`~array_api.divide`).
1777
1796
1778
1797
Parameters
1779
1798
----------
1780
1799
x: array
1781
- input array. Should have a real-valued data type.
1800
+ input array. Should have a numeric data type.
1782
1801
1783
1802
Returns
1784
1803
-------
0 commit comments