# Natural logarithm

This topic is 4477 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Hi there! How can I compute natural logarithm only with basic arithmetic formula +,-,*,/ ? I have found some pages with Taylor series, but it is not work in whole definition scope of natural logarithm. here is one of pages http://www.efunda.com/math/taylor_series/logarithmic.cfm the best is third series, but it works only form 0.5 to infinity. thx for help!

##### Share on other sites
You can use the same series to cover x < 1/2 thanks to the relation ln(1/x) = -ln(x).

##### Share on other sites
Natural Logarithm

Just look towards the bottom.

.....................
Forum Moderators,

Can we put www.mathworld.com in a page of useful links. Not that this is a bad question but I've seen math questions pop up enough that it'd be useful if people went here first. It's where I go and I haven't had any issues finding what I need yet.

Thanks.

##### Share on other sites
I second the vote for Mathworld; a lot of 'what is the expansion for X' or 'is there a formula for Y' questions can be sorted by a quick visit over there. Plus there's lots of interesting stuff :).

##### Share on other sites
Even better estimates can be achieved using Pade approximation.
Here's an example:

Define:
P(x) = -824 - 9024*x - 17880*x2 + 17880*x4 +
9024*x5 + 824*x6
Q(x) = 189 + 4194*x + 18963*x2 + 30108*x3 +
18963*x4 + 4194*x5 + 189*x6

For any x>0:
Log[x] ~= P(x) / Q(x)

This approximation gives its best results near x=1.
If you want to sacrifice this in order to get a better approximation for bigger x, you can perturb this function using Chebyshev polynomial and get something like:

P(x) = -3361863335 - 41216492700*x - 84220506435*x2 +
84220506435*x4 + 41216492700*x5 +
3361863335*x6

Q(x) = 738676107 + 18554747202*x + 87388990245*x2 +
140109217500*x3 + 87388990245*x4 +
18554747202*x5 + 738676107*x6

Where for each x>0:

Log[x] ~= P(x) / Q(x)

##### Share on other sites
The cordic method is also interesting. With a few precomputed tables you can get a fast answer with good precision. The function below computes the log of a number between 1 and 2. If you know log(2), you can compute the log of any number using this formula:

log(2^k * m) = k*log(2) + log(m)

double cordic_log_table[54]={  0.4054651081081643848591511414269916713238,  0.223143551314209764857565687634632922709,  0.1177830356563834557359626842298894189298,  0.06062462181643483993820353816772694699466,  0.03077165866675368732785500469617545604706,  0.01550418653596525447868614833168976474553,  0.00778214044205494896028207918448060809169,  0.003898640415657322888520752712793182581663,  0.001951220131261749337475697174681954493281,  0.0009760859730554589247519814421139017213136,  0.0004881620795013511871808520314885981861153,  0.0002441108275273627073887611205194048125122,  0.000122062862525677370720104952805940001781,  6.103329368063852700251534222353200220823e-05,  3.051711247318637969315295588312864083491e-05,  1.525867264836239797028052261884667473169e-05,  7.629365427567572438224442754606258176864e-06,  3.814689989685889674823340497744617039189e-06,  1.907346813825409489364238850572785821669e-06,  9.536738616591882694082499792587181985937e-07,  4.768370445163234361029061785658411665167e-07,  2.384185506798575959283044553224661932234e-07,  1.192092824453544614992595777717976357479e-07,  5.960464299903385839164343998862471973865e-08,  2.980232194360611257610473446687943122058e-08,  1.490116108282535544184557106369218293374e-08,  7.450580569168252509371086489409208297729e-09,  3.725290291523020158592771622352302074432e-09,  1.862645147496233555273192905588075518608e-09,  9.31322574181797646630798226397018879652e-10,  4.65661287199319040563949556599254719913e-10,  2.328306436267645745941123891498136799783e-10,  1.164153218201585508750905972874534199946e-10,  5.820766091177334133205389932186335499864e-11,  2.910383045631018713965409983046583874966e-11,  1.455191522826097268823383745761645968742e-11,  7.275957614156956123718615614404114921854e-12,  3.637978807085095506759732028601028730463e-12,  1.818989403544202114604972069650257182616e-12,  9.09494701772514647608762548662564295654e-13,  4.547473508863607213809504027906410739135e-13,  2.273736754432062100846174835101602684784e-13,  1.136868377216095673908443122837900671196e-13,  5.68434188608063992825560487740725167799e-14,  2.842170943040360353806149754508062919497e-14,  1.421085471520190274322661706205140729874e-14,  7.105427357600976615162275603403476824686e-15,  3.552713678800494618468379569796181706171e-15,  1.776356839400248886956000226921701676543e-15,  8.881784197001248379084527239667535441357e-16,  4.440892098500625175618395146098524485339e-16,  2.220446049250312834328230454615451433835e-16};double cordic_log(double x){  double approx=1.0;  double power=0.5;  double result=0.0;  for(int i=0;i<52;++i){    double candidate_factor=1+power;    double candidate_approx=approx*candidate_factor;    if(candidate_approx<=x){      approx=candidate_approx;      result+=cordic_log_table;    }    power*=0.5;  }  return result;}

##### Share on other sites
This is a bit offtopic btw.
Quote:
 Original post by ArmitageIII87Can we put www.mathworld.com in a page of useful links.

Good idea. But personally I have found planetmath to be good(or better). It doesn't look like much, but it is.

• ### What is your GameDev Story?

In 2019 we are celebrating 20 years of GameDev.net! Share your GameDev Story with us.

(You must login to your GameDev.net account.)

• 27
• 16
• 10
• 10
• 11
• ### Forum Statistics

• Total Topics
634102
• Total Posts
3015533
×