      function bbi_qdf(n,k,p) ! bernd berg, october 24 1999.
      include '../../libs/fortran/implicit.sta'
      include '../../libs/fortran/constants.par'
      if(k.gt.n.or.n.le.0.or.k.lt.0) stop "bbi_qdf: false n or k."
      if(p.lt.zero .or. p.gt.one) stop "bbi_qdf: false p input."
c
      if(p.eq.zero.or.p.eq.one) then
        bbi_qdf=zero
        return
      end if
c
      xkp1=one*(k+1)
      xnmk=one*(n-k)
      bbi_qdf=one-beta_i(p,xkp1,xnmk)
      if(bbi_qdf.gt.half) bbi_qdf=one-bbi_qdf
c
      return
      end
