]> git.donarmstrong.com Git - lilypond.git/blob - lily/misc.cc
* scm/lily.scm (completize-formats): new function
[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--2004 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 /*
17   Return the 2-log, rounded down 
18  */
19 int
20 intlog2 (int d)
21 {
22   assert (d);
23   int i = 0;
24   while ((d != 1)) 
25     {
26       d /= 2;
27       i++;
28     }
29   
30   assert (! (d/2));
31   return i;
32 }
33
34 double
35 log_2 (double x)
36 {
37   return log (x)  /log (2.0);
38 }
39
40 Array<String>
41 split_string (String s, char c)
42 {
43   Array<String> rv; 
44   while (s.length ())
45     {
46       int i = s.index (c);
47       
48       if (i == 0)
49         {
50           s = s.nomid_string (0, 1);
51           continue;
52         }
53       
54       if (i < 0)
55         i = s.length () ;
56
57       rv.push (s.cut_string (0, i));
58       s = s.nomid_string (0, i);
59     }
60
61   return rv;
62 }