Skip to content

Instantly share code, notes, and snippets.

@blubberdiblub
Last active September 18, 2018 06:58
Show Gist options
  • Save blubberdiblub/8ed44bc31fc82dee3a7883ef1c2185d1 to your computer and use it in GitHub Desktop.
Save blubberdiblub/8ed44bc31fc82dee3a7883ef1c2185d1 to your computer and use it in GitHub Desktop.
linear sweep variant #2
private static void sweepLinear(double min, double max, int num_intervals) {
double step = (max - min) / num_intervals;
double value = min;
for (int i = 0; i <= num_intervals; i++) {
doSomethingWithValue(value);
value += step;
}
}
/* Output:
1.5
2.0
2.5
1.5
1.6
1.7000000000000002
1.8000000000000003
1.9000000000000004
2.0000000000000004
2.1000000000000005
2.2000000000000006
2.3000000000000007
2.400000000000001
2.500000000000001
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment