]> git.donarmstrong.com Git - lilypond.git/blobdiff - lily/include/misc.hh
Release: bump Welcome versions.
[lilypond.git] / lily / include / misc.hh
index 7226aceef8d7a5d31d3530c8a7c88bd78148a578..174b2f4c01663be76fed63778e558d03cf708d6f 100644 (file)
@@ -27,7 +27,26 @@ using namespace std;
 #include "interval.hh"
 
 double log_2 (double x);
-int intlog2 (int d);
+
+/*
+  Return the 2-log, rounded down
+*/
+template <class T>
+int
+intlog2 (T d)
+{
+  if (d <= 0)
+    error ("intlog2 with negative argument: " + ::to_string (d));
+  int i = 0;
+  while ((d != 1))
+    {
+      d /= 2;
+      i++;
+    }
+
+  assert (! (d / 2));
+  return i;
+}
 
 inline int
 sign (int i)