How do computers calculate the log of a value? I'm not sure if this question belongs on StackOverfl

Thomas Hubbard

Thomas Hubbard

Answered question

2022-05-22

How do computers calculate the log of a value?
I'm not sure if this question belongs on StackOverflow or here (please let me know if the former, and i'll delete this and ask there), but I was wondering how the log or ln of a value is calculated computationally with accuracy? Is some series implemented that approximates a value?
I looked into the Taylor series for the natural logarithm, but that is apparently only accurate for 0 < x < 2, and I can't find anything else. I tried looking for source code for Java's Math#log function as well to see what algorithm they implemented, but couldn't find any since it's implemented in a native language rather than in Java.

Answer & Explanation

Makai Blackwell

Makai Blackwell

Beginner2022-05-23Added 11 answers

If the computer stores a floating point number as a × 2 b for 1 a < 2 and b an integer then log e ( a × 2 b ) = log e ( a ) + b × log e ( 2 )
For example you can use the Taylor series for log e ( 1 + x ) to find log e ( a ) log e ( a ) and can store log e ( 2 ) as a constant.

Do you have a similar question?

Recalculate according to your conditions!

Ask your question.
Get an expert answer.

Let our experts help you. Answer in as fast as 15 minutes.

Didn't find what you were looking for?