Fix modulo by zero, resulting in FPE

Fix modulo zero error resulting in floating point exception, and then
crash. This was introduced in fd6ce2da11e9f2d20cb96236753662c23feaecb4.

Closes #265.