]> git.donarmstrong.com Git - lilypond.git/blob - lily/misc.cc
54da3d0f5566a035e3d804655cc3f79f90f985f8
[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
13 /*
14   Return the 2-log, rounded down
15 */
16 int
17 intlog2 (int d)
18 {
19   assert (d);
20   int i = 0;
21   while ((d != 1))
22     {
23       d /= 2;
24       i++;
25     }
26
27   assert (! (d / 2));
28   return i;
29 }
30
31 double
32 log_2 (double x)
33 {
34   return log (x) / log (2.0);
35 }
36
37 Real
38 directed_round (Real f, Direction d)
39 {
40   if (d < 0)
41     return floor (f);
42   else
43     return ceil (f);
44 }
45