Advertisement
jukaukor

e_calcul_SALE_all_base.jl

Feb 13th, 2022
26
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.10 KB | None | 0 0
  1. # calculates Euler e in different bases
  2. # aprroximation for m!,increasing m from on an
  3. # Stirling: ln(n!) = 0.5*ln(2πn) + n(ln(n)-1)
  4. # initial value of 4 until m! > 10^(n+1)
  5. # ln(10) = 2.302585092994046, ln(2pi)=ln(6.283185307179586)
  6. # Eulerin luvun e desimaalit ( n kpl)
  7. # Juhani Kaukoranta 13.2.2022
  8. function e_calcul(n,b)
  9. # n digits, b base
  10. nro="0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"
  11. print("base ",b," : ",)
  12. m = 5 # laskentatermien määrä
  13. test = (n+1)*2.302585092994046
  14. while m*(log(m)-1.0) + 0.5*log(6.283185307179586*m) <= test
  15. m += 1
  16. end
  17. if b == 2
  18. print("10.",) # eka e:n numero
  19. else print("2.",) # eka e:n numero
  20. end
  21. coef = fill(1,m) # array coef contains only 1
  22. for i in 1:n
  23. carry = 0
  24. for j in reverse(2:m)
  25. temp = coef[j]*b + carry # in base:bin 2,oct 8,dec 10,hex 16
  26. carry = div(temp,j)
  27. coef[j] = temp - carry*j
  28. end # of digit generation
  29.  
  30. print(nro[carry+1],) # prints e digits, on by one
  31. end
  32. println()
  33. end
  34.  
  35.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement