In Emacs Calculator, frequently I come up with results that that are algebraically supposed to be a whole number, but instead because of precision error they end up as some annoying value that is very close. For example, I’m expecting a 0 but get “3.69600000004e-11” which is an extremely small value close to zero. For matrices, I defined this shortcut which maps over the elements, rounding them if they are “close enough” to the whole number.

After defining the macro I inserted it into ~/.emacs.d/calc.el:

This is not the same thing as simply rounding as it only rounds if the value is very close (under 0.0000001 difference). The formula mapped over the matrix is

if(abs(round(x)-x) < 0.0000001,round(x),x)

A different approach I tried was to multiply, truncate, and reverse the multiplication, but this doesn’t work for values like 0.9999999999.