[FFmpeg-devel] [PATCH] Add ceil(log2(x)) to libavutil/common.h

Thilo Borgmann thilo.borgmann
Sun Aug 23 19:05:07 CEST 2009


Michael Niedermayer schrieb:
> On Sun, Aug 23, 2009 at 01:12:19PM +0200, Thilo Borgmann wrote:
>> Revision 1 attached.
>>
>> Regards,
>> Thilo
> 
>>  common.h |    8 ++++++++
>>  1 file changed, 8 insertions(+)
>> b50bcc4a58c74b9b0c55c9ec9466768e9ce89817  ceillog2.rev1.patch
>> Index: libavutil/common.h
>> ===================================================================
>> --- libavutil/common.h	(revision 19682)
>> +++ libavutil/common.h	(working copy)
>> @@ -225,6 +225,14 @@
>>      else               return a;
>>  }
>>  
>> +/** Computes ceil(log2(x)).
>> + * @param x value used to compute ceil(log2(x))
>> + * @return computed ceiling of log2(x)
>> + */
>> +static inline av_const int av_ceil_log2(int x) {
>> +    return x > 1 ? av_log2((x - 1) << 1) : 0;
> 
> log2(0) is meanigless, try it in your pocket calculator if you dont belive
> me.
> What iam trying to say here is that if this function does exactly
> ceil(log2(x)) then there is no x==0 case to worry about, its possible
> the actual code using this does use x==0 but then the doxy should be made
> more clear than just refering to ceil(log2(x))
> now what remains for x > 1 to be false is x==1
> av_log2((x - 1) << 1)
> av_log2(0 << 1)
> av_log2(0)
> 0 (we define av_log2(0) that way, yes)
> 
Ok thanks.

-Thilo



More information about the ffmpeg-devel mailing list