Fix % overflow on 32 bit systems

See http://php.net/manual/en/function.fmod.php
Partially fixes #1