Log Library - How is it done in the library code?
Henry Spencer
henry at zoo.toronto.edu
Wed Mar 13 02:59:43 AEST 1991
In article <1991Mar12.014416.4289 at m.cs.uiuc.edu> joshi at m.cs.uiuc.edu (Anil Joshi) writes:
>I do not want the accuracy that might have been provided in the c library
>log(). It might be spending more time than necessary to calculate more
>accurately than I want it to be.
Let's be precise. You don't *need* the accuracy of the library routine,
and you're guessing that it might be slow. The first thing for you to do
is to find out whether that guess is correct. That is *guaranteed* to be
simpler and easier than inventing an approximate-log function, and it
could very solve your problem -- implementors often put considerable effort
into making library math functions run fast.
If, and only if, your library function turns out to be unacceptably slow,
note that the exponent of your floating-point number is already a good
estimate of the (binary) logarithm of the number; extracting the exponent
and multiplying to convert it to a natural log might be good enough. It
is difficult to answer your question when you haven't said *how much*
accuracy or *how much* speed you need.
--
"But this *is* the simplified version | Henry Spencer @ U of Toronto Zoology
for the general public." -S. Harris | henry at zoo.toronto.edu utzoo!henry
More information about the Comp.lang.c
mailing list