lilypond-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Adds longas, maximas and non-standard tweaks to MultiMeasureRest (is


From: mtsolo
Subject: Re: Adds longas, maximas and non-standard tweaks to MultiMeasureRest (issue4536068)
Date: Wed, 27 Jul 2011 17:49:01 +0000


http://codereview.appspot.com/4536068/diff/30001/lily/multi-measure-rest.cc
File lily/multi-measure-rest.cc (right):

http://codereview.appspot.com/4536068/diff/30001/lily/multi-measure-rest.cc#newcode131
lily/multi-measure-rest.cc:131: int measure_duration_log = int (ceil
(duration_log));
On 2011/07/27 17:25:59, dak wrote:
On 2011/07/27 04:13:48, Keith wrote:
> To me, having done numerical work, the chain of functions you use,
int( ceil(
> -log2(x))), is easily recognizable as "find the smallest n so that 1
/ 2^n <=
> x".
>
> While log2 is inexact, the results when x is a power of 2 are exact
> (IEEE-compliant floating-point represents integers and integer
powers of 2
> exactly) so reliably 3/4 and 2/4 both come out 1 (half/minim rest).

log2 is a transcedental operation, it is not guaranteed to be exact.
logb would
be (it just returns the exponent from the floating point
representation).

Anyway, it seems like log2 is not universally available, so we should
avoid it.
The same is likely true for logb.

Why not just an array that acts as a log table?

int foo[10] = {1,2,4,8,16,32,64,128,256,512};

Or however long you need it to be, with a check to make sure we're in
bounds.  Then, a binary search will find the index you want.

http://codereview.appspot.com/4536068/



reply via email to

[Prev in Thread] Current Thread [Next in Thread]