Path: utzoo!news-server.csri.toronto.edu!cs.utexas.edu!asuvax!ncar!elroy.jpl.nasa.gov!decwrl!mejac!orchard.la.locus.com!fafnir.la.locus.com!fafnir.la.locus.com!cjkuo From: cjkuo@locus.com (Chengi Jimmy Kuo) Newsgroups: comp.lang.c Subject: Re: Log Library - How is it done in the library code? Message-ID: Date: 13 Mar 91 18:40:52 GMT References: <15438@smoke.brl.mil> <1991Mar12.014416.4289@m.cs.uiuc.edu> <1991Mar12.165943.11101@zoo.toronto.edu> <2063@gold.gvg.tek.com> Organization: Locus Computing Corporation, Los Angeles, California Lines: 29 shaunc@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@locus.com "The correct answer to an either/or question is both!"