Great function. I should find it earlier.
Will, it's a precision problem of floating point arithmetic. Try:
This little number trigger the balance. I think it's hard to overcome.
a very useful extension to the usual round functions.
one small speed improvement can be achieved. Using find is very slow. one can use logical indexing just like this:
y(x==0) = 0;
it does the same job while much faster with lager arrays.