def  find_closest(cls, w, emissions, min_match_nm):
    if min_match_nm == 0:
      b   = -1
      elt = 'None'
      return (b,elt)

    # Binary search for best match
    waves = emissions.keys()
    waves.sort()
    lo_b = 0
    hi_b = len(waves)
    b    = int(math.floor((hi_b + lo_b) / 2))
    while lo_b < hi_b:
      diff = float(waves[b]) - w
      ldiff = float('Inf')
      if b-1 >= 0:
        ldiff = float(waves[b-1]) - w
      rdiff = float('Inf')
      if b+1 <= len(waves)-1:
        rdiff = float(waves[b+1]) - w

      if abs(diff) < abs(ldiff) and abs(diff) < abs(rdiff):
        break

      if diff > 0: # too high
        hi_b = b
      else:  # too low
        lo_b = b
      b = int(math.floor((hi_b + lo_b) / 2))

    # Quality control: must be within match nm
    if abs(float(waves[b]) - w) > min_match_nm:
      b   = -1
      elt = 'None'
    else:
      elt = emissions[waves[b]]