import math


def predict_prob(length=1.0, gap_width=1.0):
    """
    Predicts the probability that the needle will hit
    one of the two parallel lines.

    length and gap_width can be scalars or arrays.
    """
    L = length
    D = gap_width

    if L > 2 * D:
        return (
            (D * (
                math.pi + 2 * math.asin(D / L) -
                4 * math.asin(2 * D / L)
            ) +
            2 * (
                math.sqrt(L * L - D * D) -
                math.sqrt(L * L - 4 * D * D)
            )) /
            (math.pi * D)
        )
    elif L > D:
        return (
            (
                2 * math.sqrt(L * L - D * D) +
                D * (2 * math.asin(D / L) - math.pi)
            ) / (math.pi * D)
        )
    else:
        return float('NaN')