Take the 2-minute tour ×
Mathematics Stack Exchange is a question and answer site for people studying math at any level and professionals in related fields. It's 100% free, no registration required.

I would like to know how are logarithms calculated by computers. The GNU C library, for example, uses a call to the fyl2x() assembler instruction, which means that logarithms are calculated directly from the hardware.

So the question is: what algorithm is used by computers to calculate logarithms?

share|improve this question
Implementation dependent. –  Quixotic Sep 1 '11 at 16:25
For the uninitiated: fyl2x() computes a binary (base-2) logarithm. –  J. M. Sep 1 '11 at 16:27
This is almost identical to the question I asked some time ago: math.stackexchange.com/questions/14066/calculator-algorithms –  John Smith Sep 1 '11 at 23:40
It’s easy. To get the algorithm, just let let a dyslexic write “logarithm”. –  Konrad Rudolph Sep 2 '11 at 12:49
@KonradRudolph LOL. Of course, there is the one about why the dyslexic, agnostic, insomniac lay awake all night last night .... –  WetSavannaAnimal aka Rod Vance Oct 6 at 2:17

3 Answers 3

All methods I have seen reduce first by dividing by the power of $2$ in the exponent and adding that exponent times $\ln(2)$ to the result. From there, the two most common methods I have seen are Taylor series for $\ln(1+x)$ and a variant of the CORDIC algorithm.

J. M. also brings up Padé approximants which I have seen used in some calculator implementations.

share|improve this answer
In QuickDraw GX, I used the CORDIC algorithm to compute trigonometric and inverse trigonometric functions as well as logarithms and exponentials on processors without FPUs. –  robjohn Sep 1 '11 at 18:07
I've seen at least one system use a Padé approximant instead of a Maclaurin series, but yes, I believe almost all implementations exploit $\log(ab)=\log\,a+\log\,b$ for range reduction... –  J. M. Sep 1 '11 at 18:08
@J. M.: Padé approximations can be better than Maclaurin series for certain functions. However, usually, the number of terms in the numerator and denominator are about the same as the number of terms in an equivalent Maclaurin series. Then there is an extra division, which can be expensive on some processors. I generally avoided them, but it is definitely worth mentioning them. Thanks. –  robjohn Sep 1 '11 at 18:14
Right, one really has to do testing if you're implementing from the bottom up. At least the OP now knows there's a lot to pick from. –  J. M. Sep 1 '11 at 18:17
A 1971 paper by J. S. Walther (PDF) describes a unified CORDIC algorithm that can be used for multiplication, division, sin, cos, tan, arctan, sinh, cosh, tanh, arctanh, ln, exp and square root. –  oosterwal Sep 1 '11 at 20:11

Read the docs and the source of the cephes library for instance. Try also these books:

See also http://stackoverflow.com/questions/2169641/where-to-find-algorithms-for-standard-math-functions.

share|improve this answer
Hastings's book is an oldie-but-goodie. If the OP doesn't need that much accuracy, the approximations given there might be adequate. –  J. M. Sep 1 '11 at 18:32

It really depends on the CPU.

For intel IA64, apparently they use Taylor series combined with a table.

More info can be found here: http://download.intel.com/technology/itj/q41999/pdf/transendental.pdf

and here: http://www.computer.org/portal/web/csdl/doi/10.1109/ARITH.1999.762822 (this pdf you can find by a google search of the title)

share|improve this answer
This book should also be of interest. –  J. M. Sep 1 '11 at 16:26
Thank you. I searched on Knuth's Art of computer programming, where he suggested another method. –  zar Sep 1 '11 at 16:36
...and I might as well: Matters Computational has a nice section on elementary function computations, including the logarithm. –  J. M. Sep 1 '11 at 18:09
Both of your links are dead btw. –  Cruncher Aug 18 at 13:29
@Cruncher: Thanks! I will try to find alternatives... –  Aryabhata Aug 19 at 16:00

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.