def Ug(M1, M2, rho, d_pc):
    """  Calculates the binding energy in joules (See Sec. 3.2 in Caballero et al. 2009).
    The '*' in Ug* denotes the approximation r ~ s for small angles.

    Args:
        M1 (float): Mass of the primary in solar units.
        M2 (float): Mass of the secondary in solar units.
        rho (float): angular separation in arcsec. 
        d_pc (float): distance in parsec.

    Returns:
        float: Binding energy in joules.

    Nominal solar values from the IAU B2 (AU) and B3 (GM) resolutions.
    Gravitational constant value from 2018 CODATA recommended values.
    """
    G = 6.67408*1E-11  # m3 kg−1 s−2
    Msol = 1.98847*1E30  # kg
    GM = 1.3271244*1E20  # m3 s-2
    s = rho * d_pc  # AU
    AU = 149597870700  # m/AU
    Ug = -G * (M1*M2 * Msol**2)/(s*AU)  # kg2 m2 s-2 = kg J (1 J = kg m2 s-2)
    return Ug