X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=lily%2Fmisc.cc;h=e7c3063df234c6ce79bca6185bf9358e837e401b;hb=73c81adad8e53e74a721ef36297b59215eaa8c05;hp=8a1a3e94ca5b627df1f500e54f64eaccdd708e07;hpb=a0c5f43a69fc72f878d7b3f635030f67f1a535db;p=lilypond.git diff --git a/lily/misc.cc b/lily/misc.cc index 8a1a3e94ca..e7c3063df2 100644 --- a/lily/misc.cc +++ b/lily/misc.cc @@ -3,60 +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 #include "misc.hh" -#include "string.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)) + 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); } -Array -split_string (String s, char c) +Real +directed_round (Real f, Direction d) { - Array rv; - while (s.length ()) - { - int i = s.index (c); - - if (i == 0) - { - s = s.nomid_string (0, 1); - continue; - } - - if (i < 0) - i = s.length () ; - - rv.push (s.cut_string (0, i)); - s = s.nomid_string (0, i); - } + if (d < 0) + return floor (f); + else + return ceil (f); +} + + - return rv; +/* + 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); }