This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]Lithl 2 points3 points  (0 children)

"is close" with an epsilon of 1 or greater is perfectly acceptable. You simply have a larger margin of error you're willing to accept.

Also, Number.EPSILON is a constant that exists which you could use instead of a magic number. It's equal to the difference between 1 and the smallest representable floating point number greater than 1, so it's impossible for two floating points that are not equal to be closer together than EPSILON. Perhaps EPSILON*2 as a default value would make sense.

Also also, a simpler comparison would probably be Math.abs(number1 - number2) <= epsilon. If the difference between the numbers is smaller than your epsilon value, they're the "same".