cpmidq(x,n,c)
Func
Local l,u,m
0.→l
1.→u
Local fl,fu,fmid
Local prec
0.0000001/n→prec
1.-c→fl
0.-c→fu
While u-l>prec
(u+l)/2→m
binomcdf(n,m,x)-.5*binompdf(n,m,x)-c→fmid
If fmid*fl>0 Then
m→l
fmid→fl
Else
m→u
fmid→fu
EndIf
EndWhile
(u+l)/2→m
If c>.5 and x=0 Then
0→m
ElseIf c<.5 and x=n Then
1→m
EndIf
Return m
EndFunc