Calculates x = log2 of integer i such that pow(2,x) <= i.
Intop-Log2 | Calculates x = log2 of integer i such that pow(2,x) <= i. |
Copyright | This program is free software. |
Files | |
C-kern/ | Header file Intop-Log2. |
C-kern/ | Implementation file Intop-Log2 impl. |
Functions | |
test | |
unittest_math_int_log2 | Tests log2_int. |
int_t | Extends functionality of generic integer. |
compute | |
log2_int | Returns the logarithm to base 2 as integer of an integer value. |
inline implementation | |
Macros | |
log2_int | Implements int_t.log2_int as a generic function. |
This program is free software. You can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
© 2011 Jörg Seebohn
Header file Intop-Log2.
Implementation file Intop-Log2 impl.
int unittest_math_int_log2( void )
Tests log2_int.
unsigned log2_int( unsigned i )
Returns the logarithm to base 2 as integer of an integer value. This value is the same as the index of the most significant bit.
Special case: In case the parameter value is 0 the function returns 0.
The returned value is exact if <ispowerof2_int>(i) is true else it is truncated to the next lower int value. The following equation always holds true:
i >= pow(2, log2_int(i))
i | The argument whose logarithm to base 2 is caclulated and returned. |
Macros | |
log2_int | Implements int_t.log2_int as a generic function. |
Implements int_t.log2_int as a generic function.
Tests log2_int.
int unittest_math_int_log2( void )
Extends functionality of generic integer.
struct int_t
Returns the logarithm to base 2 as integer of an integer value.
unsigned log2_int( unsigned i )