Hello,
I wrote the P() Vimscript function to compute Π. A C language compiled version
take about 2 seconds to return the result (1200 chars string).
But the Vim script take about 47 seconds.
Could I do something to speed up the script ? Thanks.
" Function Π x 1000+
fu! P()
let x=''
let k=3999
let p=0
let q=0
let t=1000
let j=0
let a=[2]
wh a[j]!=0 && k!=0
let p=1+2*k
wh j<337
if !(k!=(j>2))
let x.=printf("%.3d",a[j-2]%t+q/p/t)
en
let q=a[j]*k+q%p*t
let a[j]=q/p
call add(a,0)
let j+=1
endw
let j=0
let q=0
let a[j]+=2
let k-=1
endw
retu x
endf
" echo 'End Function Π'
The P() function return, 1200 figures :
14159265358979323846264338327950288419716939937510582097494459230781640
62862089986280348253421170679821480865132823066470938446095505822317253
59408128481117450284102701938521105559644622948954930381964428810975665
93344612847564823378678316527120190914564856692346034861045432664821339
36072602491412737245870066063155881748815209209628292540917153643678925
90360011330530548820466521384146951941511609433057270365759591953092186
11738193261179310511854807446237996274956735188575272489122793818301194
91298336733624406566430860213949463952247371907021798609437027705392171
76293176752384674818467669405132000568127145263560827785771342757789609
17363717872146844090122495343014654958537105079227968925892354201995611
21290219608640344181598136297747713099605187072113499999983729780499510
59731732816096318595024459455346908302642522308253344685035261931188171
01000313783875288658753320838142061717766914730359825349042875546873115
95628638823537875937519577818577805321712268066130019278766111959092164
20198938095257201065485863278865936153381827968230301952035301852968995
77362259941389124972177528347913151557485724245415069595082953311686172
7855889075098381754637464939319255060400927701671139009848824012
" Computing Π is a stress test for a computer--a kind of "digital cardiogram."
" -> from the book: "Blatner, David. 1997. The Joy of Pi" .
--
--
You received this message from the "vim_dev" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php
---
You received this message because you are subscribed to the Google Groups
"vim_dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.