Intop-Log2

Calculates x = log2 of integer i such that pow(2,x) <= i.

Summary
Intop-Log2Calculates x = log2 of integer i such that pow(2,x) <= i.
CopyrightThis program is free software.
Files
C-kern/api/math/int/log2.hHeader file Intop-Log2.
C-kern/math/int/log2.cImplementation file Intop-Log2 impl.
Functions
test
unittest_math_int_log2Tests log2_int.
int_tExtends functionality of generic integer.
compute
log2_intReturns the logarithm to base 2 as integer of an integer value.
inline implementation
Macros
log2_intImplements int_t.log2_int as a generic function.

Copyright

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.

Author

© 2011 Jörg Seebohn

Files

C-kern/api/math/int/log2.h

Header file Intop-Log2.

C-kern/math/int/log2.c

Implementation file Intop-Log2 impl.

Functions

test

unittest_math_int_log2

int unittest_math_int_log2(void)

Tests log2_int.

int_t

struct int_t

Extends functionality of generic integer.

Summary
compute
log2_intReturns the logarithm to base 2 as integer of an integer value.

compute

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))

Parameter

iThe argument whose logarithm to base 2 is caclulated and returned.

inline implementation

Summary
Macros
log2_intImplements int_t.log2_int as a generic function.

Macros

log2_int

Implements int_t.log2_int as a generic function.

Calculates x = log2 of integer i such that pow(2,x) <= i.
Implements Intop-Log2.
int unittest_math_int_log2(void)
Tests log2_int.
Implements int_t.log2_int as a generic function.
struct int_t
Extends functionality of generic integer.
unsigned log2_int(unsigned i)
Returns the logarithm to base 2 as integer of an integer value.
Close