Replaces the iterative approach currently used by the standard fmod() function. Also fixes infinite looping that happens when the mirroring value is negative.