title: Unexpected integer math results on Arduino
body: <p>I'm trying to smoothly transition an RGB LED from one colour to another. As part of the logic for this I have the following function to determine how big the change will be (it multiplies by a factor <code>f</code> to avoid floating-point math):</p>
  
  <pre><code>int colorDelta(int from, int to, int f) {
    int delta;
  
    if (to == from) {
      delta = 0;
    } else {
      delta = (to - from) * f;
    }
  
    return delta;
  }
  </code></pre>
  
  <p><strong>When I call <code>colorDelta(0, 255, 1000)</code> I expect the result to be <code>-255000</code> but instead the function returns <code>7144</code>.</strong></p>
  
  <p>I've tried performing the operation as directly as possible for debugging, but <code>Serial.print((0 - 255) * 1000, DEC);</code> also writes <code>7144</code> to the serial port.</p>
  
  <p>What have I foolishly overlooked here? I'd really like to see the (smoothly transitioning) light. ;)</p>