]> git.donarmstrong.com Git - lilypond.git/blob - lily/misc.cc
Update.
[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--2005 Han-Wen Nienhuys <hanwen@cs.uu.nl>
7   Jan Nieuwenhuizen <janneke@gnu.org>
8 */
9
10 #include <math.h>
11
12 #include "misc.hh"
13 #include "string.hh"
14
15 /*
16   Return the 2-log, rounded down
17 */
18 int
19 intlog2 (int d)
20 {
21   assert (d);
22   int i = 0;
23   while ((d != 1))
24     {
25       d /= 2;
26       i++;
27     }
28
29   assert (! (d / 2));
30   return i;
31 }
32
33 double
34 log_2 (double x)
35 {
36   return log (x) / log (2.0);
37 }
38
39 Array<String>
40 split_string (String s, char c)
41 {
42   Array<String> rv;
43   while (s.length ())
44     {
45       int i = s.index (c);
46
47       if (i == 0)
48         {
49           s = s.nomid_string (0, 1);
50           continue;
51         }
52
53       if (i < 0)
54         i = s.length ();
55
56       rv.push (s.cut_string (0, i));
57       s = s.nomid_string (0, i);
58     }
59
60   return rv;
61 }