title: Why don't the absolute value methods on signed integers return unsigned values?
body: <p>The following code fails to compile:</p>
  
  <pre><code>fn main() {
      let x = (-5i32).abs();
  
      let z: u32 = x;
  }
  </code></pre>
  
  <p>with the message:</p>
  
  <pre class="lang-none prettyprint-override"><code>error[E0308]: mismatched types
   --&gt; src/main.rs:4:18
    |
  4 |     let z: u32 = x;
    |                  ^ expected u32, found i32
  </code></pre>
  
  <p>Reading <a href="https://doc.rust-lang.org/std/primitive.i32.html#method.abs" rel="noreferrer">the documentation</a>, it looks the choice of <code>i32</code> stems from the fact that <code>i32::min_value()</code> has no positive representation in <code>i32</code>. However, it <em>would</em> have a positive representation in <code>u32</code>, which can represent numbers twice as large.</p>
  
  <p>I'm learning the language, and want to understand why certain design decisions were made so that I can develop good habits. I find this one confusing. Can someone explain why it works this way instead of just returning a <code>u32</code>, which would seem to be the semantically correct type?</p>