Intop-Log10

Calculates x = log10 of integer i such that pow(10,x) <= i.

Summary
Intop-Log10Calculates x = log10 of integer i such that pow(10,x) <= i.
CopyrightThis program is free software.
Files
C-kern/api/math/int/log10.hHeader file Intop-Log10.
C-kern/math/int/log10.cImplementation file Intop-Log10 impl.
Functions
test
unittest_math_int_log10Tests implementation of log10_int.
int_t
compute
log10_intReturns the logarithm to base 2 as integer of an integer value.
log10_int32Implements log10_int for 32 bit values.
log10_int64Implements log10_int for 64 bit values.
inline implementation
Functions
log10_intImplements int_t.log10_int.

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

© 2012 Jörg Seebohn

Files

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

Header file Intop-Log10.

C-kern/math/int/log10.c

Implementation file Intop-Log10 impl.

Functions

Summary
test
unittest_math_int_log10Tests implementation of log10_int.

test

unittest_math_int_log10

int unittest_math_int_log10(void)

Tests implementation of log10_int.

int_t

Summary
compute
log10_intReturns the logarithm to base 2 as integer of an integer value.
log10_int32Implements log10_int for 32 bit values.
log10_int64Implements log10_int for 64 bit values.

compute

log10_int

unsigned log10_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.

This function is generic in that it accepts either 32 or 64 bit unsigned integers and selects the corresponding implementation.

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(10, log10_int(i))

Parameter

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

log10_int32

unsigned log10_int32(uint32_t i)

Implements log10_int for 32 bit values.

log10_int64

unsigned log10_int64(uint64_t i)

Implements log10_int for 64 bit values.

inline implementation

Functions

log10_int

Implements int_t.log10_int.  TODO: reimplement it with _Generic

Calculates x = log10 of integer i such that pow(10,x) <= i.
Implements Intop-Log10.
int unittest_math_int_log10(void)
Tests implementation of log10_int.
Implements int_t.log10_int.
unsigned log10_int(unsigned i)
Returns the logarithm to base 2 as integer of an integer value.
unsigned log10_int32(uint32_t i)
Implements log10_int for 32 bit values.
unsigned log10_int64(uint64_t i)
Implements log10_int for 64 bit values.
Close