"""
ITU-R BT.1361
=============

Define transfer functions from *ITU-R BT.1361*.

References
----------
-   :cite:`InternationalTelecommunicationUnion1998` : International
    Telecommunication Union. (1998). Recommendation ITU-R BT.1361 -
    Worldwide unified colorimetry and related characteristics of
    future television and imaging systems
    https://www.itu.int/dms_pubrec/itu-r/rec/bt/\
R-REC-BT.1361-0-199802-W!!PDF-E.pdf
"""
import numpy as np

from colour.algebra import spow
from colour.utilities import (
    as_float_array,
    as_float,
)


def oetf_BT1361_extended(L):
    """
    Define the opto-electronic transfer functions (OETF) for *ITU-R BT.1361* extended
    color gamut.

    Parameters
    ----------
    L
        Scene *Luminance* :math:`L`.

    Returns
    -------
    :class:`numpy.floating` or :class:`numpy.ndarray`
        Corresponding non-linear primary signal :math:`V`.

    Notes
    -----
    +------------+-----------------------+---------------+
    | **Domain** | **Scale - Reference** | **Scale - 1** |
    +============+=======================+===============+
    | ``L``      | [-0.25, 1.33]         | [-0.25, 1.33] |
    +------------+-----------------------+---------------+

    +------------+-----------------------+---------------+
    | **Range**  | **Scale - Reference** | **Scale - 1** |
    +============+=======================+===============+
    | ``E``      | [-1, -1]              | [-1, 1]       |
    +------------+-----------------------+---------------+

    References
    ----------
    :cite:`InternationalTelecommunicationUnion1998`

    Examples
    --------
    >>> oetf_BT1361_extended(0.18)  # doctest: +ELLIPSIS
    0.4090077288641...
    """

    L = as_float_array(L)

    E = np.where(
        L >= 0,
        np.where(
            L >= 0.018,
            1.099 * spow(L, 0.45) - 0.099,  # [0.018, 1.33] range
            4.500 * L,  # [0, 0.018] range
        ),
        np.where(
            L <= -0.0045,
            4.500 * L,  # [-0.0045, 0] range
            -(spow(1.099 * (-4 * L), 0.45) - 0.099)
            / 4,  # [-0.25, -0.0045] range
        ),
    )

    return as_float(E)

@@ -551,16 +551,92 @@
 at,%0A)%0A%0A%0A
+L_LINEAR_THRESHOLD_POSITIVE = 0.018%0AL_LINEAR_THRESHOLD_NEGATIVE = -0.0045%0A%0A%0A
 def oetf
@@ -975,17 +975,18 @@
  :math:%60
-V
+E'
 %60.%0A%0A    
@@ -1346,32 +1346,36 @@
 +---------------
+----
 +%0A    %7C **Range*
@@ -1408,32 +1408,36 @@
  %7C **Scale - 1**
+    
  %7C%0A    +========
@@ -1472,32 +1472,36 @@
 +===============
+====
 +%0A    %7C %60%60E%60%60   
@@ -1499,55 +1499,59 @@
  %60%60E
+p'
 %60%60    
- 
- 
 %7C %5B-
-1, -1%5D              %7C %5B-1, 1%5D      
+0.25, 1.152...%5D     %7C %5B-0.25, 1.152...%5D
  %7C%0A 
@@ -1602,24 +1602,28 @@
 ------------
+----
 +%0A%0A    Refer
@@ -1802,16 +1802,164 @@
 8641...%0A
+    %3E%3E%3E oetf_BT1361_extended(-0.25)  # doctest: +ELLIPSIS%0A    -0.25%0A    %3E%3E%3E oetf_BT1361_extended(1.33)  # doctest: +ELLIPSIS%0A    1.1504846663972...%0A
     %22%22%22%0A
@@ -1991,16 +1991,17 @@
 )%0A%0A    E
+p
  = np.wh
@@ -2056,22 +2056,83 @@
    L %3E= 
-0.018,
+L_LINEAR_THRESHOLD_POSITIVE,%0A            # L in %5B0.018, 1.33%5D range
 %0A       
@@ -2170,24 +2170,37 @@
 099,
-  # %5B0.018, 1.33
+%0A            # L in %5B0, 0.018
 %5D ra
@@ -2229,28 +2229,8 @@
 * L,
-  # %5B0, 0.018%5D range
 %0A   
@@ -2276,54 +2276,71 @@
  %3C= 
--0.0045,%0A            4.500 * L,  # %5B-0.0045, 0
+L_LINEAR_THRESHOLD_NEGATIVE,%0A            # L in %5B-0.25, -0.0045
 %5D ra
@@ -2361,21 +2361,16 @@
   -(
-spow(
 1.099 * 
 (-4 
@@ -2369,16 +2369,19 @@
 9 * 
+spow
 (-4 * L
-)
 , 0.
@@ -2413,34 +2413,69 @@
 / 4,
-  # %5B-0.25, -0.0045%5D range
+%0A            # L in %5B-0.0045, 0%5D range%0A            4.500 * L,
 %0A   
@@ -2510,10 +2510,11 @@
 _float(E
+p
 )%0A

Fix typo in ITU-R BT.1361 implementation + added doctest cases