Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # calculates Euler e in different bases
- # aprroximation for m!,increasing m from on an
- # Stirling: ln(n!) = 0.5*ln(2πn) + n(ln(n)-1)
- # initial value of 4 until m! > 10^(n+1)
- # ln(10) = 2.302585092994046, ln(2pi)=ln(6.283185307179586)
- # Eulerin luvun e desimaalit ( n kpl)
- # Juhani Kaukoranta 13.2.2022
- function e_calcul(n,b)
- # n digits, b base
- nro="0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"
- print("base ",b," : ",)
- m = 5 # laskentatermien määrä
- test = (n+1)*2.302585092994046
- while m*(log(m)-1.0) + 0.5*log(6.283185307179586*m) <= test
- m += 1
- end
- if b == 2
- print("10.",) # eka e:n numero
- else print("2.",) # eka e:n numero
- end
- coef = fill(1,m) # array coef contains only 1
- for i in 1:n
- carry = 0
- for j in reverse(2:m)
- temp = coef[j]*b + carry # in base:bin 2,oct 8,dec 10,hex 16
- carry = div(temp,j)
- coef[j] = temp - carry*j
- end # of digit generation
- print(nro[carry+1],) # prints e digits, on by one
- end
- println()
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement