Boost C++ Libraries: Ticket #9802: It seems as if integer division is being returned as a floating point https://svn.boost.org/trac10/ticket/9802 <pre class="wiki">#include &lt;iostream&gt; #include &lt;boost/multiprecision/cpp_int.hpp&gt; int main() { const boost::multiprecision::cpp_int max = 6; const boost::multiprecision::cpp_int factor = 4; const boost::multiprecision::cpp_int result = factor * factor * (max/factor); std::cout &lt;&lt; max &lt;&lt; '/' &lt;&lt; factor &lt;&lt; " = " &lt;&lt; max/factor &lt;&lt; std::endl; std::cout &lt;&lt; result &lt;&lt; std::endl; const boost::multiprecision::cpp_int result2 = 4 * 4 * (6/4); std::cout &lt;&lt; result2 &lt;&lt; std::endl; } --- 6/4 = 1 24 16 </pre><p> The documentations states that the result of arithmetic is, "An unmentionable-type expression template type when <a class="missing wiki">ExpressionTemplates</a> is true." The return type though seems questionable when doing integer arithmetic it currently is returning floating point instead of integer values. So for example when you do 6 / 4 you get 1.5 instead of 1. </p> en-us Boost C++ Libraries /htdocs/site/boost.png https://svn.boost.org/trac10/ticket/9802 Trac 1.4.3 anonymous Fri, 21 Mar 2014 22:07:05 GMT component changed; owner set https://svn.boost.org/trac10/ticket/9802#comment:1 https://svn.boost.org/trac10/ticket/9802#comment:1 <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">multiprecision</span> </li> </ul> Ticket Steven Watanabe Fri, 21 Mar 2014 22:31:01 GMT <link>https://svn.boost.org/trac10/ticket/9802#comment:2 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/9802#comment:2</guid> <description> <p> This is happening because the expression template system is re-associating the operations in number::do_multiplies. </p> <div class="wiki-code"><div class="code"><pre> <span class="k">template</span> <span class="o">&lt;</span><span class="k">class</span> <span class="nc">Exp</span><span class="o">&gt;</span> <span class="kt">void</span> <span class="n">do_multiplies</span><span class="p">(</span><span class="k">const</span> <span class="n">Exp</span><span class="o">&amp;</span> <span class="n">e</span><span class="p">,</span> <span class="k">const</span> <span class="n">detail</span><span class="o">::</span><span class="n">divides</span><span class="o">&amp;</span><span class="p">)</span> <span class="p">{</span> <span class="k">typedef</span> <span class="k">typename</span> <span class="n">Exp</span><span class="o">::</span><span class="n">left_type</span> <span class="n">left_type</span><span class="p">;</span> <span class="k">typedef</span> <span class="k">typename</span> <span class="n">Exp</span><span class="o">::</span><span class="n">right_type</span> <span class="n">right_type</span><span class="p">;</span> <span class="n">do_multiplies</span><span class="p">(</span><span class="n">e</span><span class="p">.</span><span class="n">left</span><span class="p">(),</span> <span class="k">typename</span> <span class="n">left_type</span><span class="o">::</span><span class="n">tag_type</span><span class="p">());</span> <span class="n">do_divide</span><span class="p">(</span><span class="n">e</span><span class="p">.</span><span class="n">right</span><span class="p">(),</span> <span class="k">typename</span> <span class="n">right_type</span><span class="o">::</span><span class="n">tag_type</span><span class="p">());</span> <span class="p">}</span> </pre></div></div><p> Note how this effectively turns ... * (a / b) into ... * a / b. </p> </description> <category>Ticket</category> </item> <item> <dc:creator>John Maddock</dc:creator> <pubDate>Wed, 26 Mar 2014 13:39:19 GMT</pubDate> <title>status changed; resolution set https://svn.boost.org/trac10/ticket/9802#comment:3 https://svn.boost.org/trac10/ticket/9802#comment:3 <ul> <li><strong>status</strong> <span class="trac-field-old">new</span> → <span class="trac-field-new">closed</span> </li> <li><strong>resolution</strong> → <span class="trac-field-new">fixed</span> </li> </ul> <p> The result isn't a floating point type: rather the expression templates can radically re-order many operations. However, this is a bug, so I've disabled some reordering operations specifically for integer types: <a class="ext-link" href="https://github.com/boostorg/multiprecision/commit/9eb732b956803f4999da50e155e757083e89beb3"><span class="icon">​</span>https://github.com/boostorg/multiprecision/commit/9eb732b956803f4999da50e155e757083e89beb3</a>. </p> Ticket