Post by bluatigro on Nov 6, 2019 10:53:41 GMT
error :
i got zero digits
code was translated from vb2005
[/p][p]global n : n = 100
notice find.pi$()
end
function string$( char$ , t )
uit$ = ""
for i = 1 to t
uit$ = uit$ + char$
next i
end function
function multiply$( a$ , f )
c = 0
uit$ = ""
for p = n to 1 step -1
h = val( mid$( a$ , p , 1 ) ) * f + c
c = int( h / 10 )
uit$ = str$( h mod 10 ) + uit$
next p
multiply$ = ui$
end function
function divide$( a$ , f )
b = 0
uit$ = ""
for p = n to 1 step -1
h = val( mid$( a$ , p , 1 ) ) + b * 10
uit$ = str$( int( h / f ) ) + uit$
b = h mod f
next p
divide$ = uit$
end function
function add$( a$ , b$ )
c = 0
uit$ = ""
for p = n to 0 step -1
a = val( mid$( a$ , p , 1 ) )
b = val( mid$( b$ , p , 1 ) )
h = a + b + c
c = int( h / 10 )
uit$ = str$( h mod 10 ) + uit$
next p
add$ = uit$
end function
function subtract$( a$ , b$ )
b = 0
uit$ = ""
for p = n to 0 step -1
a = val( mid$( a$ , p , 1 ) )
b = val( mid$( b$ , p , 1 ) )
h = a - b + 10
b = int( h / 10 )
uit$ = str$( h mod 10 ) + uit$
next p
subtract$ = uit$
end function
function is.zero( a$ )
uit = 1
for p = 0 to n
if val( mid$( a$ , p , 1 ) ) then uit = 0
next p
is.zero = uit
end function
sub arctan byref t$ , byref s$ , div
'' arctan( x ) = x - x ^ 3 / 3 + x ^ 5 / 5 ....
s$ = "1" + right$( s$ , len( s$ ) - 1 )
i = 1
w = div
s$ = divide$( s$ , w )
t$ = add$( t$ , s$ )
do
s$ = multiply$( s$ , i )
w = div * div
s$ = divide$( s$ , w )
i = i + 2
w = i
s$ = divide$( s$ , w )
t$ = subtract$( t$ , s$ )
s$ = multiply$( s$ , i )
w = div * div
s$ = divide$( s$ , w )
i = i + 2
w = i
s$ = divide$( s$ , w )
t$ = add$( t$ , s$ )
loop until is.zero( s$ )
end sub
function find.pi$()
'' pi / 4 = atan( 1 / 2 ) + atan( 1 / 3 )
uit$ = "pi = 3."
t$ = string$( "0" , n + 2 )
s$ = string$( "0" , n + 2 )
f = 2
call arctan t$ , s$ , f
f = 3
call arctan t$ , s$ , f
find.pi$ = uit$ + multiply$( t$ , 4 )
end function
[/p][p]