From 4a0a2bccb56546d7b0daf604d14956960f21d74c Mon Sep 17 00:00:00 2001 From: David Kastrup Date: Wed, 4 May 2016 22:50:36 +0200 Subject: [PATCH] Issue 4847: Let intlog2 adapt to argument precision Makes a few warnings disappear without compromising precision. --- lily/include/misc.hh | 21 ++++++++++++++++++++- lily/misc.cc | 19 ------------------- 2 files changed, 20 insertions(+), 20 deletions(-) diff --git a/lily/include/misc.hh b/lily/include/misc.hh index 7226aceef8..174b2f4c01 100644 --- a/lily/include/misc.hh +++ b/lily/include/misc.hh @@ -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 +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) diff --git a/lily/misc.cc b/lily/misc.cc index b930fd521a..6cafa2b50b 100644 --- a/lily/misc.cc +++ b/lily/misc.cc @@ -22,25 +22,6 @@ #include "offset.hh" #include "warn.hh" -/* - Return the 2-log, rounded down -*/ -int -intlog2 (int 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; -} - double log_2 (double x) { -- 2.39.2