import math


def xy_to_CCT_hernandez1999(xy):
    """
    Returns the correlated colour temperature :math:`T_{cp}` from given
    *CIE XYZ* colourspace *xy* chromaticity coordinates using
    *Javier Hernandez-Andres, Raymond L. Lee, Jr., and Javier Romero (1999)*
    method.

    Parameters
    ----------
    xy : array_like
        *xy* chromaticity coordinates.

    Returns
    -------
    numeric
        Correlated colour temperature :math:`T_{cp}`.

    References
    ----------
    .. [10]  `Calculating correlated color temperatures across the entire gamut
            of daylight and skylight chromaticities
            <http://www.ugr.es/~colorimg/pdfs/ao_1999_5703.pdf>`_,
            DOI: http://dx.doi.org/10.1364/AO.38.005703

    Examples
    --------
    >>> xy_to_CCT_hernandez1999((0.31271, 0.32902))  # doctest: +ELLIPSIS
    6500.0421533...
    """

    x, y = xy

    n = (x - 0.3366) / (y - 0.1735)
    CCT = (-949.86315 +
           6253.80338 * math.exp(-n / 0.92159) +
           28.70599 * math.exp(-n / 0.20039) +
           0.00004 * math.exp(-n / 0.07125))

    if CCT > 50000:
        n = (x - 0.3356) / (y - 0.1691)
        CCT = (36284.48953 +
               0.00228 * math.exp(-n / 0.07861) +
               5.4535e-36 * math.exp(-n / 0.01543))

    return CCT