Post Reply 
Collaborative collection of useful userRPL snippets
01-13-2019, 09:39 AM
Post: #20
RE: Collaborative collection of useful userRPL snippets
(01-12-2019 09:43 PM)cdmackay Wrote:  please consider this snippet, for an arbitrary base logarithm:

Code:
logyx: LOG SWAP LOG /

It uses the fact that logb(x) (log x to base b) is == loga(x) / loga(b), where a is any base.

I'd guess that LOG uses LN internally, so to make it just that little bit more accurate and faster I'd probably use:

Code:
\<< LN SWAP LN / \>>

The CORDIC algorithms that I know get you the natural logarithm of a number, not the decimal logarithm. Internally, the machine probably calculates \( \frac {ln(x)} {ln(10)} \) with \( ln(10) \) stored as a constant in ROM. At least that's how my floating point library does it Smile

To use this as a programmable function in its own right then use local variables:

Code:
\<< \-> b x \<< x LN b LN / \>> \>>

Store it as "LOGBX" and you can invoke it as LOGBX(2,8) for example, which should return 3.

Need to analyse the function at some point? Make it an algebraic:

Code:
\<< \-> b x 'LN(x)/LN(b)' \>>

If you now want to derive that function, you can (on a 48GX):

Code:
'LOGBX(B,X)' 'X' ∂

That gets you:

Code:
'1/X/LN(B)'
Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
RE: Collaborative collection of useful userRPL snippets - grsbanks - 01-13-2019 09:39 AM



User(s) browsing this thread: 4 Guest(s)