Path: utzoo!news-server.csri.toronto.edu!cs.utexas.edu!sdd.hp.com!spool.mu.edu!uunet!zephyr.ens.tek.com!gvgpsa!gold.gvg.tek.com!shaunc From: shaunc@gold.gvg.tek.com (Shaun Case) Newsgroups: comp.lang.c Subject: Re: Log Library - How is it done in the library code? Message-ID: <2063@gold.gvg.tek.com> Date: 12 Mar 91 19:33:43 GMT References: <15438@smoke.brl.mil> <1991Mar12.014416.4289@m.cs.uiuc.edu> <1991Mar12.165943.11101@zoo.toronto.edu> Organization: Grass Valley Group, Grass Valley, CA Lines: 32 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. I don't know if doing a trunc/round on a float, followed by a conversion to a string and then a strlen is any faster than doing a log, but I thought this might be interesting to someone anyway. Kind of neat to see a correlation between a number and its representation in C. Now, if we could only use strupr() to calculate sin and cos... :-) // Shaun // -- Shaun Case: shaunc@gold.gvg.tek.com or atman%ecst.csuchico.edu@RELAY.CS.NET or Shaun Case of 1:119/666.0 (Fidonet) or 1@9651 (WWIVnet) --- A bullet in the Bush is worth two in the hand.