title: Determine if operation will result in overflow?
body: <p>I have some classes within my application that represent physical units, for instance temperature. These classes have the ability to have some units associated with them and changed, such as Celcius and Kelvin. They also have user defined Max and Min values.</p>
  
  <p>When I want to change units I get a conversion factor between the two given units and then alter the <code>Min</code>, <code>Max</code>, and <code>Data</code> values within the class by performing some arithmetic operation with the conversion factor. </p>
  
  <pre><code>Double ConversionFactor = GetConversionFactor(curUnits, newUnits);
  Units = newUnits;
  Min *= ConversionFactor;
  Max *= ConversionFactor;
  Data *= ConversionFactor;
  </code></pre>
  
  <p>The issue I am having is that sometimes a user might allow the max and min values to be the <code>MinValue</code> and <code>MaxValue</code> of some type such as <code>Double</code>. If a user were to change units that have a conversion factor larger than 1 this will result in overflow. </p>
  
  <p><em>Is there a way in C# to detect if this overflow will happen for both overflow and underflow?</em></p>
  
  <p>From what I can tell with some tests I think I just need to check that the result of the operation does not equal positive or negative infinity? If so I can then just set the value back to either <code>MinValue</code> or <code>MaxValue</code>.</p>
  
  <p>Also, bonus question. In my testing I found that if I create a <code>Double max = Double.MaxValue</code> and add something small like 100 to it. The value does not change. </p>
  
  <p><em>Why is this?</em> Is there some threshold between <code>MaxValue</code> and <code>PositiveInfinity</code> because the precision is so low at that large of value?</p>