from pixar!ph; handle overflow correctly (previous version just punted