The fmod man page recommends this code to get the least positive residue: z = fmod(x, y); if (z < 0) z += y; That last line should be "z += fabs (y);" Otherwise, for x=-0.25 and y=-1 you get z=-1.25 which isn't what anyone is looking for. The man page could perhaps also state that the sign of y has no effect on the output, other than possibly when the result is a NaN. M.