public static float Floor(float f)
return (float) Math.Floor((double) f);
public static float PingPong(float t, float length)
t = Repeat(t, length * 2f);
return length - Math.Abs(t - length);
public static float Repeat(float t, float length)
return t - Floor(t / length) * length;
public static void Main()
for(float i = 0.0f; i < 10.0f; i += 0.1f)
Console.WriteLine($"{PingPong(i, 1)}");