A good question, and one without some standard answer (AFAIK), as the problem is not trivial.
First of all, you should read Bruce Dawson's excellent article Comparing Floating Point Numbers, 2012 Edition to get an insight into this surprisingly complex problem. The worst error you can make is to use the infamous abs(a - b) < eps
-- don't, it only works for a very limited range of floats and quickly leads to strange bugs! The second-worst error is that you only provide fixed eps
values, as the specific values depends very much on your application.
Once you understood the basic problems of float comparisons, the simplest algorithm for a vector comparison would be define two vectors as approximatively equal of each of their corresponding components are approximatively equal (and don't forget to compare the dimensions if they can be different!). However, a better approach would be to check whether the length of the difference vector is approximatively zero.
For matrices, its similar -- consider two matrices approximatively equal if all their corresponding components are approximatively equal. The analogy to the second vector algorithm (difference vector length) could be to check whether the difference matrix determinant is approximatively zero, but this is just a wild hobby-mathematician's guess.
In any case, you should not use a single eps
for the approximate comparisons, but let the user specify it, because no eps
is good for all applications, regardless of your approximate comparison algorithm. And again: Never use absolute error for approximate float comparisons!