Log Library - How is it done in the library code?
Chengi Jimmy Kuo
cjkuo at locus.com
Thu Mar 14 04:40:52 AEST 1991
shaunc at gold.gvg.tek.com (Shaun Case) writes:
>Just as a point of minor interest, you can get the exponent of the log
>of a string representation of a positive integer by doing a strlen().
>(log base 10, of course.)
>Example:
>strlen("1") -1 == 0 log == 0
>strlen("10") -1 == 1 log == 1
>.
>.
>.
>strlen("1000000") -1 == 7 log == 7
>not being a math weenie, I will venture an unsure guess that the
>maximum error using this method is ~1. If you are doing logs
>of small numbers, this is obviously unacceptable.
For this case, and you can extend this algorithm, you could use a series
of if-thens. This way, you can determine your own accuracy and rounding.
This is a slightly different way of doing table lookup and interpolation.
strlen isn't that fast.
Jimmy Kuo
--
cjkuo at locus.com
"The correct answer to an either/or question is both!"
More information about the Comp.lang.c
mailing list