Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Why not just use a lambda? All of the binding stuff has been deprecated for this kind of purpose.</p> <pre><code>double primeValue( const func1D &amp;func, const double lowerBound, const double upperBound, const double pole ) { // check bounds if( lowerBound &gt;= upperBound ) throw runtime_error( "lowerBound must be smaller than upperBound!" ); // C++0x way of writing: fullFunc(x) = func(x)/(x-a) auto fullFunc = [=](double d) { return func(d) / (d - pole); }; // pole not in domain if( pole&lt;lowerBound || pole&gt;upperBound) { cout &lt;&lt; "Case 1" &lt;&lt; endl; return integrateSimpson( fullFunc, 1000, lowerBound, upperBound ); } // pole closer to upper bound else if( upperBound-pole &lt; pole-lowerBound ) { cout &lt;&lt; "Case 2" &lt;&lt; endl; // C++0x way of writing g(x) := [f(x)-f(2a-x)]/(x-a) auto specialFirstFunc = [=](double x) -&gt; double { double numerator = func(x) - func(2*pole - x); return numerator / (x - pole); }; const double trickyPart = integrateSimpson( specialFirstFunc, 1000, pole+.000001, upperBound ); const double normalPart = integrateSimpson( fullFunc, 1000, lowerBound, 2.*pole-upperBound ); cout &lt;&lt; "Tricky part: " &lt;&lt; trickyPart &lt;&lt; endl; cout &lt;&lt; "Normal part: " &lt;&lt; normalPart &lt;&lt; endl; return trickyPart + normalPart; } else // pole closer to lower bound { cout &lt;&lt; "Case 3" &lt;&lt; endl; // C++0x way of writing g(x) := [f(x)-f(2a-x)]/(x-a) auto specialFirstFunc = [=](double x) -&gt; double { double numerator = func(x) - func(2*pole - x); return numerator / (x - pole); }; const double trickyPart = integrateSimpson( specialFirstFunc, 1000, lowerBound, pole-.00001 ); const double normalPart = integrateSimpson( fullFunc, 1000, 2.*pole-lowerBound, upperBound ); cout &lt;&lt; "Tricky part: " &lt;&lt; trickyPart &lt;&lt; endl; cout &lt;&lt; "Normal part: " &lt;&lt; normalPart &lt;&lt; endl; return trickyPart + normalPart; } } </code></pre> <p>As for whether or not you actually found a bug in MSVC, I don't know, but your solution is definitely way unnecessary - this code is far cleaner and easier to maintain.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload