implement calculator functionality in both directions