This is my notepad where i collect the useful snippets of OpenSCAD code that i use over and over. Some better curated than others, some formatted for clarity some for efficiency.
Tuesday, May 23, 2017
Round to next Power of 2
Calculate the next power of two higher than or equal to a given number
Usage:
for (i = [0: 100])
echo(i, ":", next_pow2(i));
function next_pow2(x) = pow(2, ceil(log(x)/log(2)));
No comments:
Post a Comment