Post by Psycho on Mar 25, 2008 18:18:12 GMT -5
I've used this piece of code, that I originally found on the Just Basic forum posted by SirDavid, in both Liberty Basic and Just Basic with no problems.
Running it in Run Basic causes the "Your program has exceeded the allowable execution time." error after the default 60 seconds and I can't figure out what Run Basic doesn't like about it. I've been able to trace it right up to entering the sub routine and after that I have no idea. I don't see any special syntax that RB shouldn't accept.
Any ideas?
Running it in Run Basic causes the "Your program has exceeded the allowable execution time." error after the default 60 seconds and I can't figure out what Run Basic doesn't like about it. I've been able to trace it right up to entering the sub routine and after that I have no idea. I don't see any special syntax that RB shouldn't accept.
Any ideas?
aprox=0.1
[start]
bad=0
specx=0
specdeci=0
counter2=0
counter=0
q=0
input "Enter the positive decimal to convert to a fraction.";num
print "How precise should the approximation be? Recommended"
input "value is between 0.001(more exact) and 0.2(less exact).";aprox
if num<0 then
print "Illegal!"
goto[start]
end if
for i=1 to len(str$(num))
if counter2=1 then counter=counter+1
if mid$(str$(num), i, 1)="." then counter2=1
next i
if counter>8 then
[toomany]
print "Too many digits or too precise!"
goto[start]
end if
call fract num
if bad=1 then goto[toomany]
a=instr(str$(deci), ".")
b=instr(str$(x), ".")
if a>0 then
for i=1 to a-1
hold$=hold$+mid$(str$(deci), i, 1)
next i
deci=val(hold$)
hold$=""
end if
if b>0 then
for i=1 to b-1
hold$=hold$+mid$(str$(x), i, 1)
next i
x=val(hold$)
hold$=""
end if
if denominator=0 then print "Fractional form of ";num;" is: ";intform
if denominator<>0 then print "Fractional form of ";num;" is: ";intform;" ";numerator_
;"/";denominator
if specx<>1 then
if q=1 then print "This is approximately ";intform;" ";approxnumerator;"/";_
approxdenominator
end if
if specx=1 and specdeci=1 then print "This is approximately ";intform+1
goto[start]
end
sub fract num
global intform,numerator,denominator,q,approxdenominator,approxnumerator,bad,aprox
if aprox=0 then aprox=0.01
intform=int(num)
deci=num-intform
x=1
while deci<>int(deci)
deci=deci*10
x=x*10
[redo]
if mid$(str$(deci), len(str$(deci)), 1)="0" or mid$(str$(deci), len(str$(deci)), 1)="." then
for i=1 to len(str$(deci))-1
hold$=hold$+mid$(str$(deci), i, 1)
next
if x>10000000000 then bad=1
deci=val(hold$)
goto[redo]
end if
wend
[div2]
if x/2=int(x/2) and deci/2=int(deci/2) then
x=x/2
deci=deci/2
goto[div2]
end if
[div5]
if x/5=int(x/5) and deci/5=int(deci/5) then
x=x/5
deci=deci/5
goto[div5]
end if
for i=1 to deci-1
test=x*i
y=test/deci
if abs(y-int(y))<aprox or mid$(str$(y), len(str$(y)), 1)="0" then
q=1
specdeci=i
if y-int(y)<0 then specx=int(y+1)
if y-int(y)>0 then specx=int(y)
exit for
end if
next i
numerator=deci
denominator=x
approxnumerator=specdeci
approxdenominator=specx
end sub