import math


def is_triangle_number(num):
    """Returns whether a number is a triangle number.

    A triangle number n is one for which there exists an integer x with
    n = (x^2 + x) / 2. Solving this quadratic equation gives

        x = (-1 +- sqrt(1 + 8n)) / 2

    which will be an integer if and only if 1 + 8n is a perfect square.
    Note: if 1 + 8n is a perfect square, it's square root will be odd,
    so we don't need to worry about the division by 2.

    A number is a perfect square if and only if the square of the floor of
    the square root gives back the original number.

    Note: there are other ways to solve this problem (notably, the iterative
    approach of generating triangle numbers until you either hit or pass num)
    which will work fine! In which cases would each approach be better?
    """
    discrim = 8 * num + 1
    base = int(math.sqrt(discrim))
    return base * base == discrim