查看完整版本: vb超高精度计算

john135246 2008-10-23 17:07

vb超高精度计算

我想做个程序,用 4(1-1/3+1/5。。。。。+1/2n-1)的式子算圆周率
用Timer每豪秒算一步,算n长时间使它变得极其精确
但Double只能到15位
有谁有办法达到超高的精度?(越高越好,10000位都行)

(据说string可以,但实在想不出怎么用)

Nothing 2008-10-23 21:34

晕,圆周率如果你那样算的话,计算机全死了

Nothing 2008-10-23 21:48

[color=#000000][color=#0000ff]Private[/color] [color=#0000ff]Sub[/color] Command1_Click[color=#0000cc]([/color][color=#0000cc])[/color]
    getpi [color=#ff0000]CLng[/color][color=#0000cc]([/color][color=#ff0000]InputBox[/color][color=#0000cc]([/color][color=#ff00ff]"生成多少位数(1-50000)的PI?"[/color][color=#0000cc],[/color] [color=#ff00ff]"提示"[/color][color=#0000cc],[/color] 30000[color=#0000cc])[/color][color=#0000cc])[/color]
[color=#0000ff]End[/color] [color=#0000ff]Sub[/color]





[color=#0000ff]Sub[/color] getpi[color=#0000cc]([/color]Optional [color=#0000ff]ByVal[/color] nums As Long [color=#0000cc]=[/color] 10000[color=#0000cc])[/color]
    nums [color=#0000cc]=[/color] nums [color=#0000cc]\[/color] 5
    [color=#0000ff]Dim[/color] max As Long[color=#0000cc],[/color] laptime As Single[color=#0000cc],[/color] result[color=#0000cc]([/color][color=#0000cc])[/color] As [color=#ff0000]String[/color]
   
    [color=#0000ff]Dim[/color] i As Long[color=#0000cc],[/color] j As Long[color=#0000cc],[/color] t[color=#0000cc],[/color] d As Long[color=#0000cc],[/color] g[color=#0000cc],[/color] k As Long[color=#0000cc],[/color] f[color=#0000cc]([/color][color=#0000cc])[/color]
    laptime [color=#0000cc]=[/color] Timer
    max [color=#0000cc]=[/color] 18 [color=#0000cc]*[/color] nums
    [color=#0000ff]ReDim[/color] f[color=#0000cc]([/color]0 [color=#0000ff]To[/color] max[color=#0000cc])[/color]
    [color=#0000ff]ReDim[/color] result[color=#0000cc]([/color]nums[color=#0000cc])[/color]
    [color=#0000ff]For[/color] i [color=#0000cc]=[/color] 0 [color=#0000ff]To[/color] max
        f[color=#0000cc]([/color]i[color=#0000cc])[/color] [color=#0000cc]=[/color] 20000
    [color=#0000ff]Next[/color]
    result[color=#0000cc]([/color]0[color=#0000cc])[/color] [color=#0000cc]=[/color] [color=#ff00ff]"π="[/color] [color=#0000cc]&[/color] vbCrLf
    g [color=#0000cc]=[/color] 20000
    [color=#0000ff]For[/color] j [color=#0000cc]=[/color] max [color=#0000ff]To[/color] 1 [color=#0000ff]Step[/color] [color=#0000cc]-[/color]18
        t [color=#0000cc]=[/color] 0
        
        [color=#0000ff]For[/color] i [color=#0000cc]=[/color] j [color=#0000ff]To[/color] 1 [color=#0000ff]Step[/color] [color=#0000cc]-[/color]1
            t [color=#0000cc]=[/color] t [color=#0000cc]+[/color] f[color=#0000cc]([/color]i[color=#0000cc])[/color] [color=#0000cc]*[/color] 100000
            d [color=#0000cc]=[/color] 2 [color=#0000cc]*[/color] i [color=#0000cc]+[/color] 1
            
            f[color=#0000cc]([/color]i[color=#0000cc])[/color] [color=#0000cc]=[/color] t [color=#0000cc]-[/color] [color=#ff0000]Int[/color][color=#0000cc]([/color]t [color=#0000cc]/[/color] d[color=#0000cc])[/color] [color=#0000cc]*[/color] d
            t [color=#0000cc]=[/color] [color=#ff0000]Int[/color][color=#0000cc]([/color]t [color=#0000cc]/[/color] d[color=#0000cc])[/color] [color=#0000cc]*[/color] i
        [color=#0000ff]Next[/color]
        k [color=#0000cc]=[/color] k [color=#0000cc]+[/color] 1
        result[color=#0000cc]([/color]k[color=#0000cc])[/color] [color=#0000cc]=[/color] Format[color=#0000cc]([/color][color=#ff0000]Int[/color][color=#0000cc]([/color]g [color=#0000cc]+[/color] t [color=#0000cc]/[/color] 100000[color=#0000cc])[/color] [color=#0000ff]Mod[/color] 100000[color=#0000cc],[/color] [color=#ff00ff]"00000"[/color][color=#0000cc])[/color]
        [color=#0000ff]If[/color] k [color=#0000ff]Mod[/color] 20 [color=#0000cc]=[/color] 0 [color=#0000ff]Then[/color] result[color=#0000cc]([/color]k[color=#0000cc])[/color] [color=#0000cc]=[/color] result[color=#0000cc]([/color]k[color=#0000cc])[/color] [color=#0000cc]&[/color] vbCrLf
        [color=#0000ff]If[/color] k [color=#0000ff]Mod[/color] 200 [color=#0000cc]=[/color] 0 [color=#0000ff]Then[/color] result[color=#0000cc]([/color]k[color=#0000cc])[/color] [color=#0000cc]=[/color] result[color=#0000cc]([/color]k[color=#0000cc])[/color] [color=#0000cc]&[/color] [color=#ff00ff]"---["[/color] [color=#0000cc]&[/color] k [color=#0000cc]*[/color] 5 [color=#0000cc]&[/color] [color=#ff00ff]"]---"[/color] [color=#0000cc]&[/color] vbCrLf
        g [color=#0000cc]=[/color] t [color=#0000ff]Mod[/color] 100000
    [color=#0000ff]Next[/color]
    Text1[color=#0000cc].[/color]Text [color=#0000cc]=[/color] [color=#ff0000]Join[/color][color=#0000cc]([/color]result[color=#0000cc],[/color] [color=#ff00ff]" "[/color][color=#0000cc])[/color]
    Me[color=#0000cc].[/color]Caption [color=#0000cc]=[/color] [color=#ff00ff]"计算完毕!总计用时"[/color] [color=#0000cc]&[/color] Timer [color=#0000cc]-[/color] laptime [color=#0000cc]&[/color] [color=#ff00ff]"秒!"[/color]
[color=#0000ff]End[/color] [color=#0000ff]Sub[/color]

[/color]

netice 2008-10-25 19:15

:L    我竟然看不懂VB代码了。。。。。。。
页: [1]
查看完整版本: vb超高精度计算