Click here to Skip to main content
15,887,267 members
Articles / Programming Languages / C#
Alternative
Tip/Trick

Natural Logarithms and Exponent

Rate me:
Please Sign up or sign in to vote.
5.00/5 (1 vote)
17 Jan 2012CPOL 9.4K   2   2
You should be delighted by the CORDIC approach to elementary functions computation.http://drdobbs.com/184404244[^]log10(x){ z = 0; for ( i=1; i= 1) x = x - x*2^(-i); z = z - log10(1-2^(-i)); else x = x + x*2^(-i); ...

You should be delighted by the CORDIC approach to elementary functions computation.



C#
log10(x){
   z = 0;
   for ( i=1; i=<B; i++ ){
      if (x > 1)
         x = x - x*2^(-i);
         z = z - log10(1-2^(-i));
       else
         x = x + x*2^(-i);
         z = z - log10(1+2^(-i));
   }
   return(z)
}

(In this listing, B is the desired number of bits of resolution in the result.)

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
CEO VISION fOr VISION
Belgium Belgium
I fell into applied algorithmics at the age of 16 or so. This eventually brought me to develop machine vision software as a professional. This is Dreamland for algorithm lovers.

Comments and Discussions

 
GeneralExcellent!!! I saw several posts about CORDIC functions, bu... Pin
Jacob F. W.18-Jan-12 18:34
Jacob F. W.18-Jan-12 18:34 
GeneralRe: Too glad that you liked these. The given implementation IS ... Pin
YvesDaoust18-Jan-12 22:17
YvesDaoust18-Jan-12 22:17 
Too glad that you liked these.

The given implementation IS iterative; the trick is that the log10 invocations correspond to B constant values that just need to be precomputed (log10(0.5)=-0.301030, log10(0.75)=-0.124939, log10(0.875)=-0.057992...).

You will find plenty of CORDIC implementations in various language, but it is up to you to mine the Web.

Have a look at http://www.voidware.com/cordic.htm, and also http://www.quinapalus.com/efunc.html


General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.