Residue number systems: Theory and implementation