|And if the number you are dealing with is zero....? |
There are two situations - input values and output values.
For an input value that is to be used in a calculation, there is no need to compare with epsilon, because you can do that with the result of the calculation. This is the case with the OP's problem.
If an input value is to be checked before use, as in divide by zero, or it is an output value, then the following should work:
If the value is between 1.0 and -1.0 then use epsilon, otherwise multiply the value by epsilon.
The thing to remember is the 'distance' between representable numbers.
Of course you can use an arbitrary precision value like you have done, which is perfectly fine for a lot of things, but might not work quite as well as expected in some situations.
For example, I was writing some code to deal with degrees, minutes and seconds of arc. I had to be careful with the exact value of the seconds to avoid problems with rounding up. Having 60 seconds is invalid, and requires settings seconds to zero and incrementing the minutes. So I needed 59.5 seconds or more to initiate the rounding up, while 59.4 or less does not. Using an arbitrary precision of 0.1 seconds, didn't always work, so I found myself having to use an epsilon value as well, so it would work in every situation.
Any way that is my understanding of it all.