Intop-Log10 impl

Implements Intop-Log10.

Summary
Intop-Log10 implImplements Intop-Log10.
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.
int_t
local variables
s_pow10Contains powers of 10 (10ⁿ).
compute
log10_int32Uses s_pow10 table to decrement result if necessary.
log10_int64Uses s_pow10 table to decrement result if necessary.
test

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.

int_t

Summary
local variables
s_pow10Contains powers of 10 (10ⁿ).
compute
log10_int32Uses s_pow10 table to decrement result if necessary.
log10_int64Uses s_pow10 table to decrement result if necessary.
test

local variables

s_pow10

static uint64_t s_pow10[20]

Contains powers of 10 (10ⁿ).

s_pow10[n] == 10ⁿ
s_pow10[n] == pow(10,n)

Except for (s_pow10[0]==0) instead of (s_pow10[0]==1).  The reason is that <log10_int>(0) is undefined in a mathematical sense but the implementation is defined to return 0.

compute

log10_int32

unsigned log10_int32(uint32_t i)

Uses s_pow10 table to decrement result if necessary.

log10_int64

unsigned log10_int64(uint64_t i)

Uses s_pow10 table to decrement result if necessary.

test

Calculates x = log10 of integer i such that pow(10,x) <= i.
Implements Intop-Log10.
static uint64_t s_pow10[20]
Contains powers of 10 (10ⁿ).
unsigned log10_int32(uint32_t i)
Uses s_pow10 table to decrement result if necessary.
unsigned log10_int64(uint64_t i)
Uses s_pow10 table to decrement result if necessary.
Close