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

Michael Niedermayer michaelni
Sun Aug 23 16:44:53 CEST 2009


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)

[...]
-- 
Michael     GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB

The educated differ from the uneducated as much as the living from the
dead. -- Aristotle 
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: Digital signature
URL: <http://lists.mplayerhq.hu/pipermail/ffmpeg-devel/attachments/20090823/3a90f283/attachment.pgp>



More information about the ffmpeg-devel mailing list