Log Library - How is it done in the library code?

Dave P. Schaumann dave at cs.arizona.edu
Mon Mar 11 12:55:57 AEST 1991


In article <1991Mar11.022141.12068 at m.cs.uiuc.edu> joshi at m.cs.uiuc.edu (Anil Joshi) writes:
>I need to compute natural log for some numbers. I could use the c math.h
>library outine but I do not want the accuracy of the library routine. A crude 
>approximation would suffice. Does anyone know how this is done in the c
>library routine? Is it possible to get the source code?

Trancendental functions are generally modeled with a Taylor-series expansion.
(Check your favorite calculus books for what a Taylor series is, and your
favorite numerical analysis book on how to get the best (ie most accurate)
results).

However, you might also consider using a table, and interpolating the
intermediate values.  Depending on the expected range of your arguments, and
the required accuracy of your result, this could be an effective (and quick)
method of gaining the results.

Of course, you would still have to initialize the table at the start of the
program... (yikes!  shades of another thread creeping in -- film at 11).
But if you're calling the function enough times that efficiency is a problem,
this should be all right.

-- 
Dave Schaumann | dave at cs.arizona.edu | Short .sig's rule!



More information about the Comp.lang.c mailing list