def _lmax(a, r):
    """
    Utility function giving the maximal value of the harmonic index `\\ell`
    for tabulated values of `Z^\\infty_{\\ell m}(r)`.

    INPUT:

    - ``a`` -- BH angular momentum parameter (in units of `M`, the BH mass)
    - ``r`` -- areal radius of the orbit (in units of `M`)

    OUTPUT:

    - maximal value of `\\ell` for which `Z^\\infty_{\\ell m}(r)` is tabulated

    EXAMPLES::

        sage: from kerrgeodesic_gw.zinf import _lmax
        sage: _lmax(0, 6.)
        10
        sage: _lmax(0, 40.)
        5
        sage: _lmax(0.9, 12.)
        10
        sage: _lmax(0.95, 12.)
        5

    """
    r_high_l = 20.0 if a <= 0.9 else 10.0
    l_max = 10 if r <= r_high_l else 5
    return l_max
