Fastest implementation of log2(int) and log2(float)

前端 未结 9 1471
天命终不由人
天命终不由人 2020-12-08 04:57

The question is

Are there any other (and/or faster) implementations of a basic 2log?

Applications

The log2(int) and

9条回答
  •  死守一世寂寞
    2020-12-08 05:14

        static byte FloorLog2(UInt16 value)
        {
            for (byte i = 0; i < 15; ++i)
            {
                if ((value >>= 1) < 1)
                {
                    return i;
                }
            }
            return 15;
        }
    

提交回复
热议问题