<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def freq2midi(freq):
 """ Given a frequency in Hz, returns its MIDI pitch number. """

  result = 12 * (log2(freq) - log2(FREQ_A4)) + MIDI_A4
  return nan if isinstance(result, complex) else result