Change floats to doubles and use fmod from math.h for double remainders.