Under the hood, Python's float type is a C double.
The most robust way would be to get the nearest integer to num, then test if that integers satisfies the property you're after:
import mathdef is_triangular1(x): num = (1/2) * (math.sqrt(8*x+1)-1 ) inum = int(round(num)) return inum*(inum+1) == 2*x # This line uses only integer arithmetic