import math


def KeplerSolve(M: float, e: float) -> float:
    """Solves Kepler's equation inverse problem for elliptical orbits.

    Args:
        M (float): mean anomaly
        e (float): eccentricity

    Returns:
        float: eccentric anomaly
    """
    if not 0 < e < 1:
        raise ValueError("Eccentricity of elliptical orbit required in range (0, 1)")

    # find E such that M = E - e*sin(E)
    E = M
    while not math.isclose(M, E - e * math.sin(E)):
        E = E - (E - e * math.sin(E) - M) / (1 - e * math.cos(E))
        # E = M + e * math.sin(E)
    return E