Skip to content

Instantly share code, notes, and snippets.

@bnsh
Created March 30, 2020 03:59
Show Gist options
  • Save bnsh/f862086e9c0ebcb52ecc10c0d4d11ce1 to your computer and use it in GitHub Desktop.
Save bnsh/f862086e9c0ebcb52ecc10c0d4d11ce1 to your computer and use it in GitHub Desktop.
This function (logmidpoints) will generate a list of midpoints in a log scale.
/* vim: expandtab shiftwidth=4 tabstop=4
*/
/*
* Given a min value and max value and a number of steps return an array of that many
* points from min value to max value. min value _must_ be > 0.. Likely you want
* to use 1 as min value. (the log of 0 is -Infinity, so you can't use 0...)
*/
function logmidpoints(min, max, steps) {
var points = [];
var logmax = Math.log(max);
var logmin = Math.log(min);
for (var v = logmin; v <= logmax; v += (logmax-logmin) / steps) {
points.push(Math.exp(v));
}
return points;
}
console.log(logmidpoints(0.001, 10000, 7))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment