MATH_ILog2

C Specification

#include <nitro/math.h>
int MATH_ILog2( u32 x );
 
  

Arguments

x The numeric value for which log will be computed

Return Values

The integer part of the log to the base 2 of x, where x is non-zero. In the special case where x = 0, the value -1 is returned.

Description

This function calculates the log to the base 2 for the specified value and returns the integer part of the result. This computation yields the same result as a computation that searches for the location of the first standing bit in x. But because this is a logarithm, the value in the argument must be a positive number. If the argument holds 0, the function returns -1.

For the ARM9 ARM code, which supports CLZ commands, the function becomes an inline function that computes 31 - clz(x), so it can be executed in two commands. For the ARM9 Thumb code and the ARM7, the function is implemented as a normal function.

See Also

MATH_CountLeadingZeros

Revision History

12/14/2004 Initial version