Last active
September 14, 2023 02:55
-
-
Save eush77/eb8862848ac6713e44a521ad37566501 to your computer and use it in GitHub Desktop.
Natural logarithm in Unix DC http://enwp.org/dc_(computer_program)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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