Results 1 to 8 of 8

Thread: Antilogarithm or inverse logarithm in thinBasic

  1. #1
    thinBasic author ErosOlmi's Avatar
    Join Date
    Sep 2004
    Location
    Milan - Italy
    Age
    57
    Posts
    8,777
    Rep Power
    10

    Antilogarithm or inverse logarithm in thinBasic

    I've got a request via web site contact form about the possibility to have Antilogarithm or inverse logarithm in thinBasic.

    Does someone can give me documentation links about this and/or help to build a native Math module new functions.

    Thanks a lot
    Eros
    www.thinbasic.com | www.thinbasic.com/community/ | help.thinbasic.com
    Windows 10 Pro for Workstations 64bit - 32 GB - Intel(R) Xeon(R) W-10855M CPU @ 2.80GHz - NVIDIA Quadro RTX 3000

  2. #2
    Super Moderator Petr Schreiber's Avatar
    Join Date
    Aug 2005
    Location
    Brno - Czech Republic
    Posts
    7,128
    Rep Power
    732
    Hi Eros,

    this operation is quite easy in the end, description here:
    http://mathworld.wolfram.com/Antilogarithm.html

    The code for it could look like:
    ' -- General purpose
    Function AntiLogarithm(nBase As Ext, nValue As Ext) As Ext
      
      Return nBase^nValue
    
    End Function   
    
    Function Logarithm(nBase As Ext, nValue As Ext) As Ext
      
      Return Log10(nValue)/Log10(nBase)
    
    End Function 
    
    ' -- Or to directly map to ThinBASIC LOG10, LOG2 and LOG (called LN on calculator)
    Function AntiLog10(nValue As Ext) As Ext
      
      Return 10^nValue
    
    End Function
    
    Function AntiLog2(nValue As Ext) As Ext
      
      Return 2^nValue
    
    End Function
    
    Function AntiLog(nValue As Ext) As Ext
      
      Return M_E^nValue
    
    End Function
    

    Petr
    Last edited by Petr Schreiber; 10-01-2011 at 14:36.
    Learn 3D graphics with ThinBASIC, learn TBGL!
    Windows 10 64bit - Intel Core i5-3350P @ 3.1GHz - 16 GB RAM - NVIDIA GeForce GTX 1050 Ti 4GB

  3. #3
    Super Moderator Petr Schreiber's Avatar
    Join Date
    Aug 2005
    Location
    Brno - Czech Republic
    Posts
    7,128
    Rep Power
    732
    Here test sample:
    Uses "Console"
    
    Dim result As Number
    
    result = Logarithm(3, 243) 
    PrintL "LOG3(243)   = ", result 
    PrintL "AntiLOG3("+Format$(result)+") = ", AntiLogarithm(3, result)
    PrintL    
    
    result = Log2(64) 
    PrintL "LOG2(64)    = ", result 
    PrintL "AntiLOG2("+Format$(result)+") = ", AntiLogarithm(2, result), "=", AntiLog2(result)
    PrintL    
    
    result = Log10(1000) 
    PrintL "LOG10(1000) = ", result 
    PrintL "AntiLOG2("+Format$(result)+") = ", AntiLogarithm(10, result), "=", AntiLog10(result)
    PrintL    
    
    result = Log(M_E^2) 
    PrintL "LOGe(e^2)   = ", result 
    PrintL "AntiLOGe("+Format$(result)+") = ", AntiLogarithm(M_E, result), "=", AntiLog(result)
    PrintL    
    
    WaitKey
    
    
    ' -- General purpose
    Function AntiLogarithm(nBase As Ext, nValue As Ext) As Ext
      
      Return nBase^nValue
    
    End Function   
    
    Function Logarithm(nBase As Ext, nValue As Ext) As Ext
      
      Return Log10(nValue)/Log10(nBase)
    
    End Function 
    
    ' -- Or to directly map to ThinBASIC LOG10, LOG2 and LOG (called LN on calculator)
    Function AntiLog10(nValue As Ext) As Ext
      
      Return 10^nValue
    
    End Function
    
    Function AntiLog2(nValue As Ext) As Ext
      
      Return 2^nValue
    
    End Function
    
    Function AntiLog(nValue As Ext) As Ext
      
      Return M_E^nValue
    
    End Function
    

    Petr
    Last edited by Petr Schreiber; 10-01-2011 at 14:37.
    Learn 3D graphics with ThinBASIC, learn TBGL!
    Windows 10 64bit - Intel Core i5-3350P @ 3.1GHz - 16 GB RAM - NVIDIA GeForce GTX 1050 Ti 4GB

  4. #4
    Super Moderator Petr Schreiber's Avatar
    Join Date
    Aug 2005
    Location
    Brno - Czech Republic
    Posts
    7,128
    Rep Power
    732
    Code in first reply was not correct, now fixed.


    Petr
    Learn 3D graphics with ThinBASIC, learn TBGL!
    Windows 10 64bit - Intel Core i5-3350P @ 3.1GHz - 16 GB RAM - NVIDIA GeForce GTX 1050 Ti 4GB

  5. #5
    thinBasic author ErosOlmi's Avatar
    Join Date
    Sep 2004
    Location
    Milan - Italy
    Age
    57
    Posts
    8,777
    Rep Power
    10
    Thanks a lot Petr, I will add to math arsenal!
    www.thinbasic.com | www.thinbasic.com/community/ | help.thinbasic.com
    Windows 10 Pro for Workstations 64bit - 32 GB - Intel(R) Xeon(R) W-10855M CPU @ 2.80GHz - NVIDIA Quadro RTX 3000

  6. #6
    Eros, Petr,

    AntiLog is quite an old idea from the days when we used log tables and antilog tables. You already have exp, exp2 and exp10. These are the exact equivalents of antilogs,

    so you could make antilog a synonym of exp or just persuade users to adopt exp

    Charles

  7. #7
    Super Moderator Petr Schreiber's Avatar
    Join Date
    Aug 2005
    Location
    Brno - Czech Republic
    Posts
    7,128
    Rep Power
    732
    Hi Charles,

    of course you are right

    Maybe at least the general purpose functions could have some use...

    Logarithm could be implemented as LOG(base, number) and AntiLogarithm as EXP(base, value)... as thinBASIC can parse optional number of params.


    Petr
    Learn 3D graphics with ThinBASIC, learn TBGL!
    Windows 10 64bit - Intel Core i5-3350P @ 3.1GHz - 16 GB RAM - NVIDIA GeForce GTX 1050 Ti 4GB

  8. #8
    Member Johannes's Avatar
    Join Date
    Nov 2010
    Location
    Wuustwezel, Belgium
    Age
    56
    Posts
    95
    Rep Power
    25
    Also, you only need a single logarithm and exponentation function, ideally ln (natural logarithm) and exp (exponentation of e). I agree that log2 and log10 are very useful as they will be used regularly, but other bases are not necessary.

    I also think that someone who needs base-3 logarithms (or base-pi for that matter) will be familiar with basic logarithmic rules.

    logA b = ln b / ln a = Log(b) / Log(a)

    a^b = e^(b ln a) = Exp(b * Log(a))
    Boole and Turing, help me!

    Primary programming: 200 MHz ARM StrongARM, RISC OS 4.02, BASIC V, ARM assembler.
    Secondary programming: 3.16 GHz Intel Core 2 Duo E8500, Vista Home Premium SP2, thinBasic, x86 assembler.

Members who have read this thread: 0

There are no members to list at the moment.

Posting Permissions

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