Skip to content

Instantly share code, notes, and snippets.

@eush77
Last active September 14, 2023 02:55
Show Gist options
  • Save eush77/eb8862848ac6713e44a521ad37566501 to your computer and use it in GitHub Desktop.
Save eush77/eb8862848ac6713e44a521ad37566501 to your computer and use it in GitHub Desktop.
Natural logarithm in Unix DC http://enwp.org/dc_(computer_program)
# L (x -- y)
# Natural logarithm of `x`.
# By Taylor series expansion of `ln(x)=ln((1+t)/(1-t))`.
# See https://en.wikipedia.org/wiki/Natural_logarithm#Numerical_value
[ 1-d2+/
d2*Sk # Initialize multiplier
d*Sy # Initialize multiplier factor
0Ss # Initialize accumulator
10K^Sp # Initialize 10^k power
[ d1r/lk*ls+lsrdss # Update accumulator
-lp*d*1 [s_q]s_>_ # Check precision
lkly*sk 2+ # Update multiplier and counter
lfx
]Sf
1lfxLs
LkLyLpLfs_s_s_s_] sL
10k
5lLx 2lLx /p
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment