Skip to content

Instantly share code, notes, and snippets.

@blubberdiblub
Last active September 18, 2018 06:55
Show Gist options
  • Save blubberdiblub/e821df43b00db50bdd03a4895a6fc99f to your computer and use it in GitHub Desktop.
Save blubberdiblub/e821df43b00db50bdd03a4895a6fc99f to your computer and use it in GitHub Desktop.
linear sweep variant #3
private static void sweepLinear(double min, double max, int num_intervals) {
for (int i = 0; i <= num_intervals; i++) {
double p = (double)i / (double)num_intervals;
double q = 1.0 - p;
double value = max * p + min * q;
doSomethingWithValue(value);
}
}
/* Output:
1.5
2.0
2.5
1.5
1.6
1.7000000000000002
1.7999999999999998
1.9
2.0
2.1
2.2
2.3
2.4
2.5
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment