Board logo

标题: [基础] 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

Private Sub Command1_Click()
    getpi CLng(InputBox("生成多少位数(1-50000)的PI?", "提示", 30000))
End Sub





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


作者: netice    时间: 2008-10-25 19:15

    我竟然看不懂VB代码了。。。。。。。




欢迎光临 编程开发论坛 (http://bbs.lihuasoft.net/) Powered by Discuz! 6.0.0