title: How can I implement a min-heap of f64 with Rust's BinaryHeap?
body: <p>I want to populate a binary heap with floats--more specifically, I'd like to implement a min-heap.</p>
  
  <p>It seems that floats do not support <code>Ord</code> and thus aren't usable out of the box. My attempts to wrap them have so far failed. However it seems that if I could wrap them then I could also implement <code>Ord</code> in such a way that it would effectively make <code>BinaryHeap</code> a min-heap.</p>
  
  <p>Here's an example of a wrapper I tried:</p>
  
  <pre><code>#[derive(PartialEq, PartialOrd)]
  struct MinNonNan(f64);
  
  impl Eq for MinNonNan {}
  
  impl Ord for MinNonNan {
      fn cmp(&amp;self, other: &amp;MinNonNan) -&gt; Ordering {
          let ord = self.partial_cmp(other).unwrap();
          match ord {
              Ordering::Greater =&gt; Ordering::Less,
              Ordering::Less =&gt; Ordering::Greater,
              Ordering::Equal =&gt; ord
          }
      }
  }
  </code></pre>
  
  <p>The problem is <code>pop</code> returns the values as though it were a max-heap.</p>
  
  <p>What exactly do I need to do to populate a <code>BinaryHeap</code> with <code>f64</code> values as a min-heap?</p>