Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
|
|
@ -0,0 +1,30 @@
|
|||
Imports System.Math
|
||||
Imports System.Console
|
||||
|
||||
Module Module1
|
||||
|
||||
Function CalcAGM(ByVal a As Double, ByVal b As Double) As Double
|
||||
Dim c As Double, d As Double = 0, ld As Double = 1
|
||||
While ld <> d : c = a : a = (a + b) / 2 : b = Sqrt(c * b)
|
||||
ld = d : d = a - b : End While : Return b
|
||||
End Function
|
||||
|
||||
Function DecSqRoot(ByVal v As Decimal) As Decimal
|
||||
Dim r As Decimal = CDec(Sqrt(CDbl(v))), t As Decimal = 0, d As Decimal = 0, ld As Decimal = 1
|
||||
While ld <> d : t = v / r : r = (r + t) / 2
|
||||
ld = d : d = t - r : End While : Return t
|
||||
End Function
|
||||
|
||||
Function CalcAGM(ByVal a As Decimal, ByVal b As Decimal) As Decimal
|
||||
Dim c As Decimal, d As Decimal = 0, ld As Decimal = 1
|
||||
While ld <> d : c = a : a = (a + b) / 2 : b = DecSqRoot(c * b)
|
||||
ld = d : d = a - b : End While : Return b
|
||||
End Function
|
||||
|
||||
Sub Main(ByVal args As String())
|
||||
WriteLine("Double result: {0}", CalcAGM(1.0, DecSqRoot(0.5)))
|
||||
WriteLine("Decimal result: {0}", CalcAGM(1D, DecSqRoot(0.5D)))
|
||||
If System.Diagnostics.Debugger.IsAttached Then ReadKey()
|
||||
End Sub
|
||||
|
||||
End Module
|
||||
|
|
@ -0,0 +1,36 @@
|
|||
Imports System.Math
|
||||
Imports System.Console
|
||||
Imports BI = System.Numerics.BigInteger
|
||||
|
||||
Module Module1
|
||||
|
||||
Function BIP(ByVal leadDig As Char, ByVal numDigs As Integer) As BI
|
||||
BIP = BI.Parse(leadDig & New String("0"c, numDigs))
|
||||
End Function
|
||||
|
||||
Function IntSqRoot(ByVal v As BI, ByVal res As BI) As BI ' res is the initial guess of the square root
|
||||
Dim d As BI = 0, dl As BI = 1
|
||||
While dl <> d : IntSqRoot = v / res : res = (res + IntSqRoot) / 2
|
||||
dl = d : d = IntSqRoot - res : End While
|
||||
End Function
|
||||
|
||||
Function CalcByAGM(ByVal digits As Integer) As BI
|
||||
Dim a As BI = BIP("1"c, digits), ' value is 1, extended to required number of digits
|
||||
c as BI, ' a temporary variable for swapping a and b
|
||||
diff As BI = 0, ldiff As BI = 1 ' difference of a and b, last difference
|
||||
CalcByAGM = BI.Parse(String.Format("{0:0.00000000000000000}", ' initial value of square root of 0.5
|
||||
Sqrt(0.5)).Substring(2) & New String("0"c, digits - 17))
|
||||
CalcByAGM = IntSqRoot(BIP("5"c, (digits << 1) - 1), CalcByAGM) ' value is now the square root of 0.5
|
||||
While ldiff <> diff : c = a : a = (a + CalcByAGM) >> 1 : CalcByAGM = IntSqRoot(c * CalcByAGM, a)
|
||||
ldiff = diff : diff = a - CalcByAGM : End While
|
||||
End Function
|
||||
|
||||
Sub Main(ByVal args As String())
|
||||
Dim digits As Integer = 25000
|
||||
If args.Length > 0 Then Integer.TryParse(args(0), digits) : _
|
||||
If digits < 1 OrElse digits > 999999 Then digits = 25000
|
||||
WriteLine("0.{0}", CalcByAGM(digits))
|
||||
If System.Diagnostics.Debugger.IsAttached Then ReadKey()
|
||||
End Sub
|
||||
|
||||
End Module
|
||||
Loading…
Add table
Add a link
Reference in a new issue