Boost C++ Libraries: Ticket #12261: LT_HalfPrevLoT and GT_HalfSuccHiT are not symmetrical https://svn.boost.org/trac10/ticket/12261 <p> Reusing low boost conversion policies to implement my own roundToInt method... </p> <p> If you try the following code: </p> <pre class="wiki">template &lt;class To, class From&gt; struct NumericRangeCheckerTraits { typedef To target_type; typedef From source_type; typedef From argument_type; }; struct ToTextOverflowHandlerPolicy { void operator() ( boost::numeric::range_check_result result) { switch (result) { case boost::numeric::cInRange: std::cout &lt;&lt; "the value is in range"&lt;&lt; std::endl; break; case boost::numeric::cNegOverflow: case boost::numeric::cPosOverflow: std::cout &lt;&lt; "the value is out of range"&lt;&lt; std::endl; break; } }; }; double dmax = std::numeric_limits&lt;int&gt;::max() + 0.5; double dmin = std::numeric_limits&lt;int&gt;::min() - 0.5; boost::numeric::convdetail::generic_range_checker&lt;NumericRangeCheckerTraits&lt;int, double&gt;, boost::numeric::convdetail::LT_HalfPrevLoT&lt;NumericRangeCheckerTraits&lt;int, double&gt;&gt;, boost::numeric::convdetail::GT_HalfSuccHiT&lt;NumericRangeCheckerTraits&lt;int, double&gt;&gt;, ToTextOverflowHandlerPolicy&gt;::validate_range(dmax); boost::numeric::convdetail::generic_range_checker&lt;NumericRangeCheckerTraits&lt;int, double&gt;, boost::numeric::convdetail::LT_HalfPrevLoT&lt;NumericRangeCheckerTraits&lt;int, double&gt;&gt;, boost::numeric::convdetail::GT_HalfSuccHiT&lt;NumericRangeCheckerTraits&lt;int, double&gt;&gt;, ToTextOverflowHandlerPolicy&gt;::validate_range(dmin); </pre><p> You will get: </p> <pre class="wiki">the value is out of range the value is in range </pre><p> When they should be both out of range. </p> <p> This is because GT_HalfSuccHiT should implement range_check_result as such: </p> <pre class="wiki">static range_check_result apply ( argument_type s ) { return s &gt; static_cast&lt;S&gt;(bounds&lt;T&gt;::highest()) + static_cast&lt;S&gt;(0.5) ? cPosOverflow : cInRange ; </pre><p> instead of using &gt;=. </p> <p> The comment to describe GT_HalfSuccHiT should be changed as well to: </p> <pre class="wiki">// s &gt; Highest(T) + 0.5 ? cPosgOverflow : cInRange </pre> en-us Boost C++ Libraries /htdocs/site/boost.png https://svn.boost.org/trac10/ticket/12261 Trac 1.4.3 viboes Mon, 08 Aug 2016 22:28:49 GMT owner changed https://svn.boost.org/trac10/ticket/12261#comment:1 https://svn.boost.org/trac10/ticket/12261#comment:1 <ul> <li><strong>owner</strong> changed from <span class="trac-author">viboes</span> to <span class="trac-author">Vladimir Batov</span> </li> </ul> Ticket Vladimir Batov Mon, 08 Aug 2016 23:02:27 GMT owner, component changed https://svn.boost.org/trac10/ticket/12261#comment:2 https://svn.boost.org/trac10/ticket/12261#comment:2 <ul> <li><strong>owner</strong> changed from <span class="trac-author">Vladimir Batov</span> to <span class="trac-author">Fernando Cacciola</span> </li> <li><strong>component</strong> <span class="trac-field-old">convert</span> → <span class="trac-field-new">numeric</span> </li> </ul> <p> I do not believe that is a Boost.Convert issue. I am under impression that it is Boost.<a class="missing wiki">NumericConversion</a> by Fernando. </p> Ticket anonymous Fri, 12 Aug 2016 19:49:12 GMT <link>https://svn.boost.org/trac10/ticket/12261#comment:3 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/12261#comment:3</guid> <description> <p> This is indeed an issue on Boost.<a class="missing wiki">NumericConversion</a> and I'll try to take a detailed look next week. </p> </description> <category>Ticket</category> </item> </channel> </rss>