如何在vb.net中计算pi到一百万或更多的数字? [英] How do I calculate pi to one million and more digits in vb.net?
本文介绍了如何在vb.net中计算pi到一百万或更多的数字?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何在vb.net中计算pi到100万位?我在c ++中看过一个,但是在vb.net中我想要它。
到目前为止我的代码:
How would I calculate pi to one million digits in vb.net? I have seen one in c++, but in vb.net I would like it.
My code so far:
Public Class Form1
Dim n As Integer = 0
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
If n >= 20 Then
Exit Sub
End If
TextBox1.Text += " " + (Math.PI * n).ToString()
n += 1
Dim x As String = n / 5
If x.Contains(".") Then
If x = 0.2 Then
Exit Sub
End If
TextBox1.Text &= " "
End If
End Sub
End Class
推荐答案
这不起作用。甚至没有点。
数学.Pi [ ^ ]返回double
- 这是π
的近似值,它是准确的在double
的范围内:它是一个64位的值,它能做的最好是15位。
所以取这个值并使用它作为一个百万位π发生器的基础永远不会工作......
相反,如果你想计算到一个高位数,你必须为此目的实施一种算法: http://en.wikipedia.org/wiki/Pi [ ^ ]提及一些并提供参考。
That is not going to work. Not even slightly.
Math.Pi[^] returns adouble
- which is an approximation toπ
that is accurate within the bounds of adouble
: it's a 64bit value, and the best it can do is 15 digits.
So taking that value and using it as the base for a million-digit π generator is never, ever going to work...
Instead, if you want to calculate to a high digit count, you are going to have to implement one of teh algorithms for that purpose: http://en.wikipedia.org/wiki/Pi[^] mentions a few and provides references.
这篇关于如何在vb.net中计算pi到一百万或更多的数字?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文