You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Calculates an implementation-dependent approximation to the hyperbolic tangent, having domain ``[-infinity, +infinity]`` and codomain ``[-1, +1]``, for each element ``x_i`` of the input array ``x``.
1469
+
r"""
1470
+
Calculates an implementation-dependent approximation to the hyperbolic tangent for each element ``x_i`` of the input array ``x``.
1471
+
1472
+
The mathematical definition of the hyperbolic tangent is
where :math:`\operatorname{sinh}(x)` is the hyperbolic sine and :math:`\operatorname{cosh}(x)` is the hyperbolic cosine.
1471
1478
1472
1479
**Special cases**
1473
1480
1474
-
For floating-point operands,
1481
+
.. note::
1482
+
For all operands, ``tanh(-x)`` must equal ``-tanh(x)``.
1483
+
1484
+
For real-valued floating-point operands,
1475
1485
1476
1486
- If ``x_i`` is ``NaN``, the result is ``NaN``.
1477
1487
- If ``x_i`` is ``+0``, the result is ``+0``.
1478
1488
- If ``x_i`` is ``-0``, the result is ``-0``.
1479
1489
- If ``x_i`` is ``+infinity``, the result is ``+1``.
1480
1490
- If ``x_i`` is ``-infinity``, the result is ``-1``.
1481
1491
1492
+
For complex floating-point operands, let ``a = real(x_i)``, ``b = imag(x_i)``, and
1493
+
1494
+
.. note::
1495
+
For complex floating-point operands, ``tanh(conj(x))`` must equal ``conj(tanh(x))``.
1496
+
1497
+
- If ``a`` is ``+0`` and ``b`` is ``+0``, the result is ``+0 + 0j``.
1498
+
- If ``a`` is a nonzero finite number and ``b`` is ``+infinity``, the result is ``NaN + NaN j``.
1499
+
- If ``a`` is ``+0`` and ``b`` is ``+infinity``, the result is ``+0 + NaN j``.
1500
+
- If ``a`` is a nonzero finite number and ``b`` is ``NaN``, the result is ``NaN + NaN j``.
1501
+
- If ``a`` is ``+0`` and ``b`` is ``NaN``, the result is ``+0 + NaN j``.
1502
+
- If ``a`` is ``+infinity`` and ``b`` is a positive (i.e., greater than ``0``) finite number, the result is ``1 + 0j``.
1503
+
- If ``a`` is ``+infinity`` and ``b`` is ``+infinity``, the result is ``1 + 0j`` (sign of the imaginary component is unspecified).
1504
+
- If ``a`` is ``+infinity`` and ``b`` is ``NaN``, the result is ``1 + 0j`` (sign of the imaginary component is unspecified).
1505
+
- If ``a`` is ``NaN`` and ``b`` is ``+0``, the result is ``NaN + 0j``.
1506
+
- If ``a`` is ``NaN`` and ``b`` is a nonzero number, the result is ``NaN + NaN j``.
1507
+
- If ``a`` is ``NaN`` and ``b`` is ``NaN``, the result is ``NaN + NaN j``.
1508
+
1509
+
.. warning::
1510
+
For historical reasons stemming from the C standard, array libraries may not return the expected result when ``a`` is ``+0`` and ``b`` is either ``+infinity`` or ``NaN``. The result should be ``+0 + NaN j`` in both cases; however, for libraries compiled against older C versions, the result may be ``NaN + NaN j``.
1511
+
1512
+
Array libraries are not required to patch these older C versions, and, thus, users are advised that results may vary across array library implementations for these special cases.
1513
+
1514
+
.. note::
1515
+
The hyperbolic tangent is an analytical function on the complex plane and has no branch cuts. The function is periodic, with period :math:`\pi j`, with respect to the imaginary component and has first order poles along the imaginary line at coordinates :math:`(0, \pi (\frac{1}{2} + n))`. However, IEEE 754 binary floating-point representation cannot represent :math:`\pi / 2` exactly, and, thus, no argument value is possible such that a pole error occurs.
1516
+
1482
1517
Parameters
1483
1518
----------
1484
1519
x: array
1485
-
input array whose elements each represent a hyperbolic angle. Should have a real-valued floating-point data type.
1520
+
input array whose elements each represent a hyperbolic angle. Should have a floating-point data type.
1486
1521
1487
1522
Returns
1488
1523
-------
1489
1524
out: array
1490
-
an array containing the hyperbolic tangent of each element in ``x``. The returned array must have a real-valued floating-point data type determined by :ref:`type-promotion`.
1525
+
an array containing the hyperbolic tangent of each element in ``x``. The returned array must have a floating-point data type determined by :ref:`type-promotion`.
0 commit comments