LN(natural log)


Results 1 to 8 of 8

Thread: LN(natural log)

Threaded View

  1. #8
    anj's Avatar
    anj Guest


    Did you find this post helpful? Yes | No

    Default

    I rewrote the "by calc" section from the following site
    http://www.emesys.com/BS2math3.htm
    into a subroutine and ended up with the following
    Result is the log value multiplied by 1000
    Accuracy should be good enough for what you are doing.
    If you want to know HOW it works, you need to read the text, i just rewrote it and it worked so i was happy.
    Code:
    LogNo  VAR WORD     ' Number to get log of
    
    k      VAR byte     'loop var
    X      Var WORD     'temp for processing
    X1     var word     'temp for squaring
    LgX    var word     'lg ( base 2 ) of y the mantissa
    cc     var byte     'characteristic of log
    
    Lg     var word     'log base 2
    Log    var word     'log base 10
    Ln     var word     'log base e
    '---------------------------------------------------
    etc
    etc
    Logno = varX  'ie no to get result
    gosub getlog
    ' now ref to Lg, Ln or Log as reqd
    
    GetLog:
      cc = NCD LogNo - 1
      X = LogNo << ( 15 - cc )
      LgX = 0
      for k = 14 to 0 step -1
        X1 = X**X
        if X1.bit15 then
          lgx = lgx | ( dcd k )   'set the bit
          X = X1
        else
          X = ( X1 << 1 ) + 1    'shift er over
        endif  
      next k  
      lg  = cc*1000 + ( lgx**20000/10 )
      log = ( lg ** 19728 )
      ln  = ( lg ** 45426 )
    return  
    ---------------------
    Andrew
    Last edited by ScaleRobotics; - 3rd February 2011 at 11:09. Reason: added code tags

Similar Threads

  1. Gps/glcd
    By karenhornby in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 1st April 2008, 16:18
  2. math operator LOG
    By Eyal in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 22nd July 2004, 23:45
  3. Log and exponential
    By anj in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 5th March 2004, 20:03

Members who have read this thread : 0

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts