Skip to content

Instantly share code, notes, and snippets.

@jskeet
Created January 2, 2025 18:33
Show Gist options
  • Save jskeet/7d825e0e003c9139c3d626fcb295ffe2 to your computer and use it in GitHub Desktop.
Save jskeet/7d825e0e003c9139c3d626fcb295ffe2 to your computer and use it in GitHub Desktop.
double[] inputs = { -10.0, -6.0, -5.0, -4.0, -3.0, -2.0, -1.0, 0.0, 0.001, 1.0, 2.0, 5.0, 6.0, 10.0, 12.0, 15.0, 25.0 };
foreach (var input in inputs)
{
var output = WrapPositive(10L, input);
Console.WriteLine($"{input} => {output}");
}
double WrapPositive(double periodicDistance, double position) =>
(position % periodicDistance + periodicDistance) % periodicDistance;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment