title: Under what conditions does Math.Log(x,y) throw DivideByZeroException?
body: <p>I recently received a crash log with the following call stack:</p>
  
  <pre><code>&gt; System.DivideByZeroException: Attempted to divide by zero.    at
  &gt; System.Math.Log(Double a, Double newBase)
  </code></pre>
  
  <p>But, from what I can tell <a href="https://msdn.microsoft.com/en-us/library/hd50b6h5(v=vs.110).aspx" rel="nofollow noreferrer">from the docs</a>, this exception shouldn't be thrown and I've tried all sorts of inputs in a test program and haven't been able to reproduce this exception.  Also, the code calling this function has a limited range of inputs so I think the input values are ok.</p>
  
  <p>I'm wondering if this might be the result of a bad plugin (my program hosts plugins typically written in C++) or some other piece of code leaving a floating point error on the FPU?</p>
  
  <p>Any thoughts on how to prevent or at least protect myself from this?</p>
  
  <hr>
  
  <p>Update to answer some questions in the comments:</p>
  
  <ul>
  <li>This is happening in .NET 4 Client Profile</li>
  <li>The app is built in Release mode</li>
  <li>I don't have access to the input values that cause the exception</li>
  <li>I can't really disable the plugins - this is a music app hosting VST plugins.</li>
  <li>The exception is extremely rare - I've see it just twice with thousands of users running the app everyday so trying this in vs out of app context won't really help.</li>
  <li>The newBase parameter is always 10.0 on the call stack where the exception was reported - so the non-epsilon comparison to 1.0 shouldn't be the issue.</li>
  </ul>
  
  <hr>
  
  <p>Update 2: turns out this customer could reproduce the problem and found it to be related to licensing of one of his plugins.  Once the licensing issue was fixed the issue went away.  That's a way too mystical for my liking but at this stage I'm just glad he's got a fix.  To quote the customer it "eventually crashed every host in different ways".</p>