If I want to check that positive float A is less than the inverse square of another positive float B (in C99), could something go wrong if B is very small?
I could imagine checking it like
But if B is small enough, would this possibly result in infinity? If that were to happen, would the code still work correctly in all situations?
In a similar vein, I might do
... which might be slightly better because B*B might be zero if B is small (is this true?)
Finally, a solution that I can't imagine being wrong is
which I don't think would ever result in zero division, but still might be problematic if A is close to zero.
So basically, my questions are:
- Can 1/X ever be infinity if X is greater than zero (but small)?
- Can X*X ever be zero if X is greater than zero?
- Will comparisons with infinity work the way I would expect them to?
EDIT: for those of you who are wondering, I ended up doing
I did it in that order as it is visually unambiguous which multiplication occurs first.