code: def _psturng(q, r, v):
      
      if q < 0.:
          raise ValueError('q should be >= 0')
  
      opt_func = lambda p, r, v : abs(_qsturng(p, r, v) - q)
  
      if v == 1:
          if q < _qsturng(.9, r, 1):
              return .1
          elif q > _qsturng(.999, r, 1):
              return .001
          return 1. - fminbound(opt_func, .9, .999, args=(r,v))
      else:
          if q < _qsturng(.1, r, v):
              return .9
          elif q > _qsturng(.999, r, v):
              return .001
          return 1. - fminbound(opt_func, .1, .999, args=(r,v))
docs: scalar version of psturng