]> git.donarmstrong.com Git - lilypond.git/blob - lily/misc.cc
(Module):
[lilypond.git] / lily / misc.cc
1 /*
2   misc.cc -- implement various stuff
3
4   source file of the GNU LilyPond music typesetter
5
6   (c) 1997--2006 Han-Wen Nienhuys <hanwen@xs4all.nl>
7   Jan Nieuwenhuizen <janneke@gnu.org>
8 */
9
10
11 #include "misc.hh"
12 #include "std-string.hh"
13
14 /*
15   Return the 2-log, rounded down
16 */
17 int
18 intlog2 (int d)
19 {
20   assert (d);
21   int i = 0;
22   while ((d != 1))
23     {
24       d /= 2;
25       i++;
26     }
27
28   assert (! (d / 2));
29   return i;
30 }
31
32 double
33 log_2 (double x)
34 {
35   return log (x) / log (2.0);
36 }
37
38 Array<std::string>
39 split_string (std::string s, char c)
40 {
41   Array<std::string> rv;
42   while (s.length ())
43     {
44       ssize i = s.find (c);
45
46       if (i == 0)
47         {
48           s = s.substr (1, s.length () -1);
49           continue;
50         }
51
52       if (i == NPOS)
53         i = s.length ();
54
55       rv.push (s.substr (0, i));
56       s = s.substr (i, s.length () - i);
57     }
58
59   return rv;
60 }
61
62
63 Real
64 directed_round (Real f, Direction d)
65 {
66   if (d < 0)
67     return floor (f);
68   else
69     return ceil (f);
70 }
71