Log Library - How is it done in the library code?
Shaun Case
shaunc at gold.gvg.tek.com
Wed Mar 13 05:33:43 AEST 1991
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 at gold.gvg.tek.com or atman%ecst.csuchico.edu at RELAY.CS.NET
or Shaun Case of 1:119/666.0 (Fidonet) or 1 at 9651 (WWIVnet)
---
A bullet in the Bush is worth two in the hand.
More information about the Comp.lang.c
mailing list