Boost C++ Libraries: Ticket #7905: boost::math::policies::raise_rounding_error returns the wrong min/max values for ignore_error and errno_on_error https://svn.boost.org/trac10/ticket/7905 <p> In the documentation for the rounding functions, in "Table 6. Possible Actions for Rounding Errors", it says that the round function will return "the largest representable value of the <strong>target</strong> integer type (or the most negative value if the argument to the function was less than zero). </p> <p> However, the specializations of the raise_rounding_error function for ignore_error and errno_on_error call std::numeric_limits min() and max() with the source type rather than the result type. </p> <p> For example, calling </p> <pre class="wiki">iround(INT_MAX + 1.0) </pre><p> will return </p> <pre class="wiki">static_cast&lt;int&gt;(std::numeric_limits&lt;double&gt;::max()) </pre><p> rather than </p> <pre class="wiki">static_cast&lt;int&gt;(std::numeric_limits&lt;int&gt;::max()) </pre><p> as was specified. </p> en-us Boost C++ Libraries /htdocs/site/boost.png https://svn.boost.org/trac10/ticket/7905 Trac 1.4.3 benkerby@… Fri, 18 Jan 2013 23:26:46 GMT <link>https://svn.boost.org/trac10/ticket/7905#comment:1 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/7905#comment:1</guid> <description> <p> Note that the function reads: </p> <pre class="wiki"> // This may or may not do the right thing, but the user asked for the error // to be ignored so here we go anyway: return std::numeric_limits&lt;T&gt;::is_specialized ? (val &gt; 0 ? (std::numeric_limits&lt;T&gt;::max)() : -(std::numeric_limits&lt;T&gt;::max)()): val; </pre><p> but it should read </p> <pre class="wiki"> // This may or may not do the right thing, but the user asked for the error // to be ignored so here we go anyway: return std::numeric_limits&lt;TargetType&gt;::is_specialized ? (val &gt; 0 ? (std::numeric_limits&lt;TargetType&gt;::max)() : (std::numeric_limits&lt;TargetType&gt;::min)()): val; </pre><p> Two changes: </p> <ul><li>template specialized on the <a class="missing wiki">TargetType</a> </li><li>return the minimum value rather than the negative version of the max value (important for unsigned types) </li></ul> </description> <category>Ticket</category> </item> <item> <author>benkerby@…</author> <pubDate>Fri, 18 Jan 2013 23:29:04 GMT</pubDate> <title>component changed; owner set https://svn.boost.org/trac10/ticket/7905#comment:2 https://svn.boost.org/trac10/ticket/7905#comment:2 <ul> <li><strong>owner</strong> set to <span class="trac-author">John Maddock</span> </li> <li><strong>component</strong> <span class="trac-field-old">None</span> → <span class="trac-field-new">math</span> </li> </ul> Ticket John Maddock Wed, 13 Feb 2013 19:06:21 GMT status changed https://svn.boost.org/trac10/ticket/7905#comment:3 https://svn.boost.org/trac10/ticket/7905#comment:3 <ul> <li><strong>status</strong> <span class="trac-field-old">new</span> → <span class="trac-field-new">assigned</span> </li> </ul> <p> Confirmed, testing fix. </p> Ticket John Maddock Thu, 14 Feb 2013 18:20:06 GMT status changed; resolution set https://svn.boost.org/trac10/ticket/7905#comment:4 https://svn.boost.org/trac10/ticket/7905#comment:4 <ul> <li><strong>status</strong> <span class="trac-field-old">assigned</span> → <span class="trac-field-new">closed</span> </li> <li><strong>resolution</strong> → <span class="trac-field-new">fixed</span> </li> </ul> <p> (In <a class="changeset" href="https://svn.boost.org/trac10/changeset/82885" title="Fix raise_rounding_error to return the correct result (and type) when ...">[82885]</a>) Fix raise_rounding_error to return the correct result (and type) when an error occurs. Fixes <a class="closed ticket" href="https://svn.boost.org/trac10/ticket/7905" title="#7905: Bugs: boost::math::policies::raise_rounding_error returns the wrong min/max ... (closed: fixed)">#7905</a>. </p> Ticket