Shop OBEX P1 Docs P2 Docs Learn Events
Natural Logs? — Parallax Forums

Natural Logs?

mhamen3mhamen3 Posts: 69
edited 2013-04-27 10:17 in Propeller 1
Does anyone know how I can perform a floating point natural log in SPIN? Float32 has logs and exponentials but nothing for natural logs. I'm a bit stuck.

Any help would be very appreciated. Thanks

-Marc

Comments

  • Duane DegnDuane Degn Posts: 10,588
    edited 2013-04-16 16:40
    F32's "Log" method finds the natural log of a number.
    PUB Log(a) | b{{
      Logarithm, base e.
    

    Post #92 of this thread has the most up to date version of F32 I know of.
  • Tracy AllenTracy Allen Posts: 6,664
    edited 2013-04-17 09:17
    Multiply: If you have the logarithm in one base, you can convert it to any other base by muliplying by a constant.

    ln(x) = 2.302585092994046 * log10(x)
  • Mark_TMark_T Posts: 1,981
    edited 2013-04-17 09:38
    And a possibly interesting point of trivia, John Napier (inventor of logarithms) was responsible for popularising the decimal point... All in all
    a pretty decent legacy to leave us.
  • Martin_HMartin_H Posts: 4,051
    edited 2013-04-18 06:31
    Mark_T wrote: »
    And a possibly interesting point of trivia, John Napier (inventor of logarithms) was responsible for popularising the decimal point... All in all
    a pretty decent legacy to leave us.

    John Napier is more than just an interesting point of Trivia. He also invented a kind of calculating machine called Napier's bones (see http://en.wikipedia.org/wiki/Napier's_bones ).
  • Bobb FwedBobb Fwed Posts: 1,119
    edited 2013-04-19 15:32
    I use this.
    PRI ln (val)
    '' Thanks to lonesock (Jonathan)
    
      RETURN FLT.FDiv(FLT.FFloat(val - $3F7A_7DD1), 12102203.0)
    
  • Duane DegnDuane Degn Posts: 10,588
    edited 2013-04-19 20:10
    Bobb Fwed wrote: »
    I use this.
    PRI ln (val)
    '' Thanks to lonesock (Jonathan)
    
      RETURN FLT.FDiv(FLT.FFloat(val - $3F7A_7DD1), 12102203.0)
    

    That just went sailing over my head. Any hints on why that works?
  • Mark_TMark_T Posts: 1,981
    edited 2013-04-21 04:36
    Bobb Fwed wrote: »
    I use this.
    PRI ln (val)
    '' Thanks to lonesock (Jonathan)
    
      RETURN FLT.FDiv(FLT.FFloat(val - $3F7A_7DD1), 12102203.0)
    

    Really. Its not a logarithm though.

    [ edit: after some testing: Its a poor approximation, several % error, so very limited in utility ]
  • Bobb FwedBobb Fwed Posts: 1,119
    edited 2013-04-22 14:12
    Mark_T wrote: »
    Really. Its not a logarithm though.

    [ edit: after some testing: Its a poor approximation, several % error, so very limited in utility ]
    Yeah, sorry, I should have mentioned that (though I had forgot at the time of posting). It is just an approximation. For my purposes it works great. I use it for temperature measuring on an RC circuit, and is only off by about 1 to 1.5 degrees (F) at it's worst.
  • Tracy AllenTracy Allen Posts: 6,664
    edited 2013-04-22 17:37
    That came from this thread, Is-there-a-SPIN-version-of-Float-Log?
  • DroneDrone Posts: 433
    edited 2013-04-27 00:34
    Multiply: If you have the logarithm in one base, you can convert it to any other base by multiplying by a constant.

    ln(x) = 2.302585092994046 * log10(x)

    Yes indeed. However, please allow me to expand...

    The number 2.30258... Tracy refers to is simply ln(x) / log(x); or loge(x) / log10(x) to be a bit more rigorous.

    In-general, to compute the base y logarithm of x given the ability to find only base z logarithms:

    logy(x) = logz(x) / logz(y)
  • Duane DegnDuane Degn Posts: 10,588
    edited 2013-04-27 10:17
    mhamen3 wrote: »
    Float32 has logs and exponentials but nothing for natural logs.

    I just took a look at Float32. Its "Log" method is base e so you'd use it to take the natural log of something. The method "Log10" is the base ten log.

    As mentioned by Drone and others there are ways to converting the log of one base to another but that's not need in the case of a the natural log.
Sign In or Register to comment.