X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=lily%2Fmisc.cc;h=e7c3063df234c6ce79bca6185bf9358e837e401b;hb=45e73c21395bfa26f928c216fc6ee72fc9fa68d9;hp=036cbd7e507d48e009808c307153b2d2b3a8829e;hpb=c659cb200486c2f908703696a1b2873e78c8160a;p=lilypond.git diff --git a/lily/misc.cc b/lily/misc.cc index 036cbd7e50..e7c3063df2 100644 --- a/lily/misc.cc +++ b/lily/misc.cc @@ -3,36 +3,55 @@ source file of the GNU LilyPond music typesetter - (c) 1997--2004 Han-Wen Nienhuys - Jan Nieuwenhuizen + (c) 1997--2006 Han-Wen Nienhuys + Jan Nieuwenhuizen */ -#include "misc.hh" -#include +#include "misc.hh" /* - Return the 2-log, rounded down - */ + Return the 2-log, rounded down +*/ int intlog2 (int d) { assert (d); - int i=0; - while ((d != 1)) + int i = 0; + while ((d != 1)) { d /= 2; i++; } - - assert (! (d/2)); + + assert (! (d / 2)); return i; } double log_2 (double x) { - return log (x) /log (2.0); + return log (x) / log (2.0); +} + +Real +directed_round (Real f, Direction d) +{ + if (d < 0) + return floor (f); + else + return ceil (f); } - + + +/* + 0 at threshold, 1 at 0, with 1/x falloff. + */ +Real +peak_around (Real epsilon, Real threshold, Real x) +{ + if (x < 0) + return 1.0; + return max (- epsilon * (x - threshold) / ((x + epsilon) * threshold), 0.0); +}