def gamma(num: float) -> float:
    if num <= 0:
        raise ValueError("math domain error")
    if num > 171.5:
        raise OverflowError("math range error")
    elif num - int(num) not in (0, 0.5):
        raise NotImplementedError("num must be an integer or a half-integer")
    elif num == 0.5:
        return sqrt(pi)
    else:
        return 1.0 if num == 1 else (num - 1) * gamma(num - 1)