import math


def KL(q, p):
    """function to compute KL-divergence between two Bernoulli Distributions

    Args:
        q (float): probability of success of posterior distribution
        p ([type]): probability of success of prior distribution

    Returns:
        float: KL-divergence value
    """
    t1 = 0.0
    t2 = 0.0
    if p < 1e-10:
        p = 1e-10
    if p > 1 - 1e-10:
        p = 1-1e-10
    try:
        t1 = 0.0 if q == 0.0 else q * math.log(q / p)
        t2 = 0.0 if q == 1.0 else (1 - q) * math.log((1 - q) / (1 - p))
    except:
        print('Math Domain Error', p, q)
    return t1 + t2