码迷,mamicode.com
首页 > 其他好文 > 详细

函数ut_2_log

时间:2015-12-01 01:29:07      阅读:158      评论:0      收藏:0      [点我收藏+]

标签:

计算某个数的对数(最大的)

例如 16 计算后为 4 

2的4次方为16

 

例如15 计算后为3

2的3次方为8

 

/*************************************************************//**
Calculates fast the 2-logarithm of a number, rounded upward to an
integer.
@return    logarithm in the base 2, rounded upward */
UNIV_INLINE
ulint
ut_2_log(
/*=====*/
    ulint    n)    /*!< in: number != 0 */
{
    ulint    res;

    res = 0;

    ut_ad(n > 0);

    n = n - 1;

    for (;;) {
        n = n / 2;

        if (n == 0) {
            break;
        }

        res++;
    }

    return(res + 1);
}

 

函数ut_2_log

标签:

原文地址:http://www.cnblogs.com/taek/p/5008830.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!