Mark Wickens

10 GOSUB400:IFp>1 ORp=<0 THEN*
15 IFp=1 THENx=0:GOTO80
20 IFn=1 THENq=p:p=q/2:GOSUB"LIB0:S6410":GOSUB400:x=y*y:p=q:GOTO80
30 IFn=2 THENx=-2*LNp:GOTO80
40 GOSUB"LIB0:S6410":GOSUB400:x=y:y=x*x:x=n+SQR(2*n)*x+2/3*(y-1)+x*(y-7)/9/SQR(2*n)-2/405/n*(y*(3*y+7)-16):IFx<0 THENx=0
50 IFn>100 THEN80
60 b=x:GOSUB100:IFn<31 THENIFABS(b-x)>1E-4 THEN60
80 y=x:RETURN
100 q=p:GOSUB"LIB0:S6220":GOSUB400:p=y
110 z=EXP(((n-1)*LN(x/n)-LN(4*PI*x)+n-x-1/n/6)/2)
120 x=x+(p-q)/z:p=q:x=ROUND(x,-6):RETURN
400 ONERRORGOTO500:RETURN
500 IFERR=1 THENCLS:ONERRORGOTO0
510 sr=1:RESUME80