import math


def f2E(f, e):
    """
    Function: f2E
    Purpose: Maps true anomaly angles into eccentric anomaly angles.
        This function requires the orbit to be either circular or
        non-rectilinar elliptic orbit.
    Inputs:
        f = true anomaly angle (rad)
        e = eccentricity (0 <= e < 1)
    Outputs:
        Ecc = eccentric anomaly (rad)
    """
    if e >= 0.0 and e < 1.0:
        Ecc = 2.0 * math.atan2(math.sqrt(1.0 - e) * math.sin(f / 2.0), math.sqrt(1.0 + e) * math.cos(f / 2.0))
        return Ecc
    raise ValueError('Error: f2E() received e = {}, the value of e should be 0 <= e < 1'.format(str(e)))