I adapted a similar program found in a magazine eons ago, I hope you won't mind me posting it, who knows, it may give you some insight.
did your code work before you replaced the integer array with string? if so then please post that code as it would help to diagnose the problem
Code: Select all
Declare Sub series (a() As Long, f As LongInt)
Declare Sub multiply (a() As Long, f As LongInt)
Declare Sub subtract (d() As Long, t() As Long)
Declare Sub lsqrpoly (x() As Double, y() As Double, c() As Double, e As Double)
Declare Sub Add (s() As Long, t() As Long)
Declare Sub divide (a() As Long, d As LongInt)
Dim As Double c(2), x(12), y(12), ti, sp
Dim As LongInt i, n, k=2
Dim As LongInt n1
Dim As Long j, hours, minutes, seconds
Dim As String a_string, p_string
ReDim As Long pi(0), p(0)
ReDim Shared As Long power(0),temp(0)
Dim Shared size As LongInt
Print "please wait a few seconds";
For i = 1 To 9
k=k*2
n = k * i
x(i) = CDbl(n)
ti = Timer
n = 8 * (n \ 8) + 4
ReDim pi(n \ 8 + 2), p(n \ 8 + 2), power(n \ 8 + 2), temp(n \ 8 + 2)
size = n \ 8 + 1
series(pi(), 57)
multiply(pi(), 44)
series(p(), 239)
multiply(p(), 7)
Add(pi(), p())
series(p(), 682)
multiply(p(), 12)
subtract(pi(), p())
series(p(), 12943)
multiply(p(), 24)
Add(pi(), p())
multiply(pi(), 4)
y(i) = Timer - ti
Erase pi, p, power, temp
Print ".";
Next i
Print
lsqrpoly(x(), y(), c(), 0)
Input "how many digits do you want ", n
sp = c(0)
n1 = 1
For i = 1 To 2
n1 = n1 * n
sp = sp + c(i) * n1
Next i
Print "it will take aproximately "; sp; " seconds (+/- 15%)"
a_string=""
If sp>=60 Then
ti=sp/3600
hours=Int(ti)
ti=Frac(ti)*60
minutes=Int(ti)
seconds=Int(Frac(ti)*60)
If hours>0 Then a_string=Str(hours)+" hours, "
If minutes>0 Then a_string+=Str(minutes)+" minutes, "
If seconds>0 Then a_string+=Str(seconds)+" seconds"
End If
if a_string<>"" then
Print "or ";a_string
end if
Input "continue ?", a_string
If Len(a_string) = 0 Then a_string = "n"
a_string = UCase(a_string)
If Left(a_string, 1) <> "Y" Then End
'input "print output to printer ?", p_string
'if len(p_string) = 0 then p_string = "n"
'p_string = ucase(left(p_string, 1))
'if p_string <> "y" then p_string = "n"
ti = Timer
n = 8 * (n \ 8) + 4
'''cls
ReDim pi(n \ 8 + 2), p(n \ 8 + 2), power(n), temp(n)
size = n \ 8 + 1
/'
series(pi(), 5)
multiply(pi(), 4)
series(p(), 239)
subtract(pi(), p())
'/
/'
series(pi(), 49)
multiply(pi(), 12)
series(p(), 57)
multiply(p(), 32)
add(pi(), p())
series(p(), 239)
multiply(p(), 5)
subtract(pi(), p())
series(p(), 110443)
multiply(p(), 12)
add(pi(), p())
'/
series(pi(), 57)
multiply(pi(), 44)
series(p(), 239)
multiply(p(), 7)
Add(pi(), p())
series(p(), 682)
multiply(p(), 12)
subtract(pi(), p())
series(p(), 12943)
multiply(p(), 24)
Add(pi(), p())
multiply(pi(), 4)
ti = Timer - ti
a_string = Str(pi(size + 1))
a_string = Left(a_string, 1) + "." + Mid(a_string, 2)
Print a_string;
'if p_string = "y" then lprint a_string;
j = 1
For i = size To 3 Step -1
a_string = Str(pi(i))
While Len(a_string) < 8
a_string = "0" + a_string
Wend
Print a_string;
'if p_string = "y" then lprint a_string;
j = j + 1
If (j * 4) Mod 60 = 0 Then Print
'if ((j * 4) mod 60 = 0) and p_string = "y" then lprint ""
Next i
Print
Print "time to compute pi, not counting printing, is: "; ti; " seconds"
'''sleep
End
Sub Add (s() As Long, t() As Long) Static
'adds t into s
Dim As LongInt carry, size, sum
Dim As Long i
carry = 0
If s(1) < t(1) Then size = t(1) Else size = s(1)
size = size + 1
For i = 2 To size
sum = t(i) + s(i) + carry
carry = sum \ 100000000
s(i) = sum - 100000000 * carry
If carry And size < UBound(s) Then
s(1) = size
s(size + 1) = carry
End If
Next i
End Sub
Sub subtract (d() As Long, t() As Long) Static
'subtract t from d
Dim As LongInt borrow, size, tmp
Dim As Long i
borrow = 0
size = d(1) + 1
For i = 2 To size
tmp = d(i) - t(i) + borrow
borrow = tmp \ 100000000
d(i) = tmp - 100000000 * borrow
If d(i) < 0 Then
d(i) = d(i) + 100000000
borrow = borrow - 1
End If
Next i
While (d(size) = 0) And (size > 0)
size = size - 1
d(1) = size
Wend
End Sub
Sub multiply (a() As Long, f As LongInt) Static
'multiplies large number in a by f
Dim As LongInt size, carry, p
Dim As Long i
size = a(1) + 1
carry = 0
For i = 2 To size
p = f * a(i) + carry
carry = p \ 100000000
a(i) = p - 100000000 * carry
Next i
If carry Then
a(1) = size
a(size + 1) = carry
End If
End Sub
Sub divide (a() As Long, d As LongInt) Static
'divides large number in a by d
Dim As LongInt remainder, size, term
Dim As Long i
remainder = 0
size = a(1) + 1
For i = size To 2 Step -1
term = 100000000 * remainder + a(i)
a(i) = term \ d
remainder = term - d * a(i)
Next i
If a(size) = 0 Then a(1) = size - 2
End Sub
Sub series (a() As Long, f As LongInt) Static
'shared power(), temp(), size
Dim As LongInt sign, d
Dim As Long i
For i = 2 To size + 1
power(i) = 0
Next i
power(size + 1) = 10000000
power(1) = size
divide(power(), f)
sign = 1
d = 3
For i = 1 To size + 1
a(i) = power(i)
Next i
Do
divide(power(), f * f)
sign = -sign
For i = 1 To size + 1
temp(i) = power(i)
Next i
divide(temp(), d)
d = d + 2
If sign > 0 Then
Add(a(), temp())
Else
subtract(a(), temp())
End If
Loop While temp(1) > 0
End Sub
Sub lsqrpoly (x() As Double, y() As Double, c() As Double, e As Double) Static
Dim As Long i, n, n1, ls, m
Dim As Double a1, a2, b1, b2, c1, d1, d2, f1, f2, l, l2, v0, v1, v2, w
m = UBound(c)
n = UBound(x)
Dim As Double c0(n), v(n), a(n), b(n)
Dim As Double d(n), c2(n), e2(n), f(n)
l = 0
n1 = m + 1
v1 = 100000000000
For i = 1 To n1
a(i) = 0
b(i) = 0
f(i) = 0
Next i
For i = 1 To n
v(i) = 0
d(i) = 0
Next i
d1 = Sqr(CDbl(n))
w = d1
For i = 1 To n
e2(i) = 1 / w
Next i
f1 = d1
a1 = 0
For i = 1 To n
a1 = a1 + x(i) * e2(i) * e2(i)
Next i
c1 = 0
For i = 1 To n
c1 = c1 + y(i) * e2(i)
Next i
b(1) = 1 / f1
f(1) = b(1) * c1
For i = 1 To n
v(i) = v(i) + e2(i) * c1
Next i
m = 1
lup0:
For i = 1 To l
c2(i) = c0(i)
Next i
l2 = l
v2 = v1
f2 = f1
a2 = a1
f1 = 0
For i = 1 To n
b1 = e2(i)
e2(i) = (x(i) - a2) * e2(i) - f2 * d(i)
d(i) = b1
f1 = f1 + e2(i) * e2(i)
Next i
f1 = Sqr(f1)
For i = 1 To n
e2(i) = e2(i) / f1
Next i
a1 = 0
For i = 1 To n
a1 = a1 + x(i) * e2(i) * e2(i)
Next i
c1 = 0
For i = 1 To n
c1 = c1 + e2(i) * y(i)
Next i
m = m + 1
i = 0
lup1:
ls = m - i
b2 = b(ls)
d1 = 0
If ls > 1 Then d1 = b(ls - 1)
d1 = d1 - a2 * b(ls) - f2 * a(ls)
b(ls) = d1 / f1
a(ls) = b2
i = i + 1
If i <> m Then GoTo lup1
For i = 1 To n
v(i) = v(i) + e2(i) * c1
Next i
For i = 1 To n1
f(i) = f(i) + b(i) * c1
c0(i) = f(i)
Next i
v0 = 0
For i = 1 To n
v0 = v0 + (v(i) - y(i)) * (v(i) - y(i))
Next i
v0 = Sqr(v0 / (n - ls - 1))
ls = m
If e = 0 Then GoTo lup2
If Abs(v1 - v0) / v0 < e Then GoTo lup4
If e * v0 > e * v1 Then GoTo lup4
v1 = v0
lup2:
If m = n1 Then GoTo lup3
GoTo lup0
lup3:
For i = 1 To ls
c0(i - 1) = c0(i)
Next i
c0(ls) = 0
ls = ls - 1
d2 = v0
GoTo lup5
lup4:
ls = 0
v0 = v2
For i = 1 To ls
c0(i) = c2(i)
Next i
GoTo lup3
lup5:
For i = 0 To ls
c(i) = c0(i)
Next i
End Sub