If you want to not divide by zero, you can just check for zero. You want to use some epsilon if you want to compare floating point numbers, 0.1 + 0.2 == 0.3 for example is false and not what you wanted most of the time. To do this properly you calculate the difference (0.1 + 0.2) - 0.3 and check if the absolute value of the difference is smaller than some tolerance, your epsilon.