staff-symbol-referencer.cc: Junk redundant functions.
[lilypond.git] / lily / misc.cc
blob85db2468cd3f51116640e95bc62c3433fb31c1b9
1 /*
2 misc.cc -- implement various stuff
4 source file of the GNU LilyPond music typesetter
6 (c) 1997--2007 Han-Wen Nienhuys <hanwen@xs4all.nl>
7 Jan Nieuwenhuizen <janneke@gnu.org>
8 */
11 #include "misc.hh"
14 Return the 2-log, rounded down
16 int
17 intlog2 (int d)
19 assert (d);
20 int i = 0;
21 while ((d != 1))
23 d /= 2;
24 i++;
27 assert (! (d / 2));
28 return i;
31 double
32 log_2 (double x)
34 return log (x) / log (2.0);
37 Real
38 directed_round (Real f, Direction d)
40 if (d < 0)
41 return floor (f);
42 else
43 return ceil (f);
49 0 at threshold, 1 at 0, with 1/x falloff.
51 Real
52 peak_around (Real epsilon, Real threshold, Real x)
54 if (x < 0)
55 return 1.0;
56 return max (- epsilon * (x - threshold) / ((x + epsilon) * threshold), 0.0);
60 0 at 0, 1 at standard_x, and increasing thereafter.
62 Real
63 convex_amplifier (Real standard_x, Real increase_factor, Real x)
65 return (exp (increase_factor * x / standard_x) - 1.0) / (exp (increase_factor) - 1.0);
68 string
69 camel_case_to_lisp_identifier (string in)
71 vector<char> out;
73 /* don't add '-' before first character */
74 out.push_back (char (tolower (in[0])));
76 for (size_t inpos = 1; inpos < in.size (); inpos++)
78 if (isupper (in[inpos]))
79 out.push_back ('-');
80 out.push_back ( char(tolower (in[inpos])));
83 string result (&out[0], out.size ());
84 replace_all (&result, '_', '-');
86 return result;