As far as I know, exact comparison doesn't make much sense with floating point values as what is intended to be 0.0001 can actually be something like 0.0001000...0001... Should I implement my own comparison function to specify precision or is there a common practice for this?

I used to use the following with C# (which, I suspect, is still wrong as a Double value can be probably uncapable of representing 0.0001 at all, even set as a constant (as Michael Borgwardt explained [here](https://stackoverflow.com/questions/8376908/can-floating-point-data-types-be-used-to-store-exact-numbers-at-all))):

```
public static bool AlmostEquals(this double x, double y, double precision = 0.0001)
{
  if (precision < 0.0)
    throw new ArgumentException();

  return Math.Abs(x - y) <= precision;
}

```

Should I do something alike in Scala?