Boost C++ Libraries: Ticket #11641: boost::multiprecision::fmod does not behave in the same way as std::fmod with neg divisor https://svn.boost.org/trac10/ticket/11641 <p> I have discovered that the replacement fmod for use with the high precision types behaves differently to the std::fmod function when using a negative divisor. </p> <p> My example is boost::multiprecision::fmod(5.5, -3.333...), this gives a remainder of -1.1666... whereas std::fmod gives 2.1666... I'm basing this expectation on the following references. </p> <p> The description of std::fmod (<a class="ext-link" href="http://en.cppreference.com/w/cpp/numeric/math/fmod"><span class="icon">​</span>http://en.cppreference.com/w/cpp/numeric/math/fmod</a>): </p> <p> "Computes the floating-point remainder of the division operation x/y" "The returned value has the same sign as x and is less or equal to y in magnitude." </p> <p> And the description of the boost::multiprecision::fmod (<a href="http://www.boost.org/doc/libs/1_59_0/libs/multiprecision/doc/html/boost_multiprecision/ref/backendconc.html#boost_multiprecision.ref.backendconc.optional_requirements_on_the_backend_type">http://www.boost.org/doc/libs/1_59_0/libs/multiprecision/doc/html/boost_multiprecision/ref/backendconc.html#boost_multiprecision.ref.backendconc.optional_requirements_on_the_backend_type</a>): </p> <p> "Performs the equivalent operation to std::fmod on arguments cb and cb2, and store the result in b. Only required when B is an floating-point type. The default version of this function is synthesised from other operations above." </p> <p> The following code illustrates the problem (with the example case that exposed it for me): </p> <div class="wiki-code"><div class="code"><pre><span class="cp">#include</span> <span class="cpf">&lt;cmath&gt;</span><span class="cp"></span> <span class="cp">#include</span> <span class="cpf">&lt;iostream&gt;</span><span class="cp"></span> <span class="cp">#include</span> <span class="cpf">&lt;iomanip&gt;</span><span class="cp"></span> <span class="cp">#include</span> <span class="cpf">&lt;limits&gt;</span><span class="cp"></span> <span class="cp">#include</span> <span class="cpf">&lt;boost/multiprecision/cpp_dec_float.hpp&gt;</span><span class="cp"></span> <span class="kt">int</span> <span class="nf">main</span> <span class="p">(</span> <span class="kt">int</span> <span class="n">argc</span> <span class="p">,</span> <span class="kt">char</span> <span class="o">*</span><span class="n">argv</span><span class="p">[]</span> <span class="p">)</span> <span class="p">{</span> <span class="c1">// This is the double precision standard impl. </span> <span class="kt">double</span> <span class="n">d1</span> <span class="o">=</span> <span class="mf">11.0</span> <span class="o">/</span> <span class="mf">2.0</span><span class="p">;</span> <span class="kt">double</span> <span class="n">d2</span> <span class="o">=</span> <span class="o">-</span><span class="mf">10.0</span> <span class="o">/</span> <span class="mf">3.0</span><span class="p">;</span> <span class="kt">double</span> <span class="n">d3</span> <span class="o">=</span> <span class="n">std</span><span class="o">::</span><span class="n">fmod</span><span class="p">(</span><span class="n">d1</span><span class="p">,</span> <span class="o">-</span><span class="n">d2</span><span class="p">);</span> <span class="c1">// this is the boost multiprecision impl. </span> <span class="n">boost</span><span class="o">::</span><span class="n">multiprecision</span><span class="o">::</span><span class="n">cpp_dec_float_100</span> <span class="n">b_11</span><span class="p">(</span><span class="s">&quot;11.0&quot;</span><span class="p">);</span> <span class="n">boost</span><span class="o">::</span><span class="n">multiprecision</span><span class="o">::</span><span class="n">cpp_dec_float_100</span> <span class="n">b_12</span><span class="p">(</span><span class="s">&quot;2.0&quot;</span><span class="p">);</span> <span class="n">boost</span><span class="o">::</span><span class="n">multiprecision</span><span class="o">::</span><span class="n">cpp_dec_float_100</span> <span class="n">b_21</span><span class="p">(</span><span class="s">&quot;-10.0&quot;</span><span class="p">);</span> <span class="n">boost</span><span class="o">::</span><span class="n">multiprecision</span><span class="o">::</span><span class="n">cpp_dec_float_100</span> <span class="n">b_22</span><span class="p">(</span><span class="s">&quot;3.0&quot;</span><span class="p">);</span> <span class="n">boost</span><span class="o">::</span><span class="n">multiprecision</span><span class="o">::</span><span class="n">cpp_dec_float_100</span> <span class="n">b1</span><span class="p">(</span><span class="n">b_11</span> <span class="o">/</span> <span class="n">b_12</span><span class="p">);</span> <span class="n">boost</span><span class="o">::</span><span class="n">multiprecision</span><span class="o">::</span><span class="n">cpp_dec_float_100</span> <span class="n">b2</span><span class="p">(</span><span class="n">b_21</span> <span class="o">/</span> <span class="n">b_22</span><span class="p">);</span> <span class="n">boost</span><span class="o">::</span><span class="n">multiprecision</span><span class="o">::</span><span class="n">cpp_dec_float_100</span> <span class="n">b3</span> <span class="o">=</span> <span class="n">boost</span><span class="o">::</span><span class="n">multiprecision</span><span class="o">::</span><span class="n">fmod</span><span class="p">(</span><span class="n">b1</span><span class="p">,</span> <span class="o">-</span><span class="n">b2</span><span class="p">);</span> <span class="n">std</span><span class="o">::</span><span class="n">cout</span> <span class="o">&lt;&lt;</span> <span class="n">std</span><span class="o">::</span><span class="n">endl</span> <span class="o">&lt;&lt;</span> <span class="s">&quot;Boost (Working) =&gt;&quot;</span> <span class="o">&lt;&lt;</span> <span class="n">std</span><span class="o">::</span><span class="n">endl</span><span class="p">;</span> <span class="n">std</span><span class="o">::</span><span class="n">cout</span> <span class="o">&lt;&lt;</span> <span class="n">std</span><span class="o">::</span><span class="n">setprecision</span><span class="p">(</span><span class="n">std</span><span class="o">::</span><span class="n">numeric_limits</span><span class="o">&lt;</span><span class="n">boost</span><span class="o">::</span><span class="n">multiprecision</span><span class="o">::</span><span class="n">cpp_dec_float_100</span><span class="o">&gt;::</span><span class="n">max_digits10</span><span class="p">);</span> <span class="n">std</span><span class="o">::</span><span class="n">cout</span> <span class="o">&lt;&lt;</span> <span class="s">&quot; Dividend: &quot;</span> <span class="o">&lt;&lt;</span> <span class="n">b1</span> <span class="o">&lt;&lt;</span> <span class="n">std</span><span class="o">::</span><span class="n">endl</span><span class="p">;</span> <span class="n">std</span><span class="o">::</span><span class="n">cout</span> <span class="o">&lt;&lt;</span> <span class="s">&quot; Divisor : &quot;</span> <span class="o">&lt;&lt;</span> <span class="o">-</span><span class="n">b2</span> <span class="o">&lt;&lt;</span> <span class="n">std</span><span class="o">::</span><span class="n">endl</span><span class="p">;</span> <span class="n">std</span><span class="o">::</span><span class="n">cout</span> <span class="o">&lt;&lt;</span> <span class="s">&quot; Result : &quot;</span> <span class="o">&lt;&lt;</span> <span class="n">b3</span> <span class="o">&lt;&lt;</span> <span class="n">std</span><span class="o">::</span><span class="n">endl</span> <span class="o">&lt;&lt;</span> <span class="n">std</span><span class="o">::</span><span class="n">endl</span><span class="p">;</span> <span class="n">std</span><span class="o">::</span><span class="n">cout</span> <span class="o">&lt;&lt;</span> <span class="s">&quot;Std =&gt;&quot;</span> <span class="o">&lt;&lt;</span> <span class="n">std</span><span class="o">::</span><span class="n">endl</span><span class="p">;</span> <span class="n">std</span><span class="o">::</span><span class="n">cout</span> <span class="o">&lt;&lt;</span> <span class="n">std</span><span class="o">::</span><span class="n">setprecision</span><span class="p">(</span><span class="n">std</span><span class="o">::</span><span class="n">numeric_limits</span><span class="o">&lt;</span><span class="kt">double</span><span class="o">&gt;::</span><span class="n">max_digits10</span><span class="p">);</span> <span class="n">std</span><span class="o">::</span><span class="n">cout</span> <span class="o">&lt;&lt;</span> <span class="s">&quot; Dividend: &quot;</span> <span class="o">&lt;&lt;</span> <span class="n">d1</span> <span class="o">&lt;&lt;</span> <span class="n">std</span><span class="o">::</span><span class="n">endl</span><span class="p">;</span> <span class="n">std</span><span class="o">::</span><span class="n">cout</span> <span class="o">&lt;&lt;</span> <span class="s">&quot; Divisor : &quot;</span> <span class="o">&lt;&lt;</span> <span class="o">-</span><span class="n">d2</span> <span class="o">&lt;&lt;</span> <span class="n">std</span><span class="o">::</span><span class="n">endl</span><span class="p">;</span> <span class="n">std</span><span class="o">::</span><span class="n">cout</span> <span class="o">&lt;&lt;</span> <span class="s">&quot; Result : &quot;</span> <span class="o">&lt;&lt;</span> <span class="n">d3</span> <span class="o">&lt;&lt;</span> <span class="n">std</span><span class="o">::</span><span class="n">endl</span> <span class="o">&lt;&lt;</span> <span class="n">std</span><span class="o">::</span><span class="n">endl</span><span class="p">;</span> <span class="n">b3</span> <span class="o">=</span> <span class="n">boost</span><span class="o">::</span><span class="n">multiprecision</span><span class="o">::</span><span class="n">fmod</span><span class="p">(</span><span class="o">-</span><span class="n">b1</span><span class="p">,</span> <span class="o">-</span><span class="n">b2</span><span class="p">);</span> <span class="n">d3</span> <span class="o">=</span> <span class="n">std</span><span class="o">::</span><span class="n">fmod</span><span class="p">(</span><span class="o">-</span><span class="n">d1</span><span class="p">,</span> <span class="o">-</span><span class="n">d2</span><span class="p">);</span> <span class="n">std</span><span class="o">::</span><span class="n">cout</span> <span class="o">&lt;&lt;</span> <span class="s">&quot;Boost (Working) =&gt;&quot;</span> <span class="o">&lt;&lt;</span> <span class="n">std</span><span class="o">::</span><span class="n">endl</span><span class="p">;</span> <span class="n">std</span><span class="o">::</span><span class="n">cout</span> <span class="o">&lt;&lt;</span> <span class="n">std</span><span class="o">::</span><span class="n">setprecision</span><span class="p">(</span><span class="n">std</span><span class="o">::</span><span class="n">numeric_limits</span><span class="o">&lt;</span><span class="n">boost</span><span class="o">::</span><span class="n">multiprecision</span><span class="o">::</span><span class="n">cpp_dec_float_100</span><span class="o">&gt;::</span><span class="n">max_digits10</span><span class="p">);</span> <span class="n">std</span><span class="o">::</span><span class="n">cout</span> <span class="o">&lt;&lt;</span> <span class="s">&quot; Dividend: &quot;</span> <span class="o">&lt;&lt;</span> <span class="o">-</span><span class="n">b1</span> <span class="o">&lt;&lt;</span> <span class="n">std</span><span class="o">::</span><span class="n">endl</span><span class="p">;</span> <span class="n">std</span><span class="o">::</span><span class="n">cout</span> <span class="o">&lt;&lt;</span> <span class="s">&quot; Divisor : &quot;</span> <span class="o">&lt;&lt;</span> <span class="o">-</span><span class="n">b2</span> <span class="o">&lt;&lt;</span> <span class="n">std</span><span class="o">::</span><span class="n">endl</span><span class="p">;</span> <span class="n">std</span><span class="o">::</span><span class="n">cout</span> <span class="o">&lt;&lt;</span> <span class="s">&quot; Result : &quot;</span> <span class="o">&lt;&lt;</span> <span class="n">b3</span> <span class="o">&lt;&lt;</span> <span class="n">std</span><span class="o">::</span><span class="n">endl</span> <span class="o">&lt;&lt;</span> <span class="n">std</span><span class="o">::</span><span class="n">endl</span><span class="p">;</span> <span class="n">std</span><span class="o">::</span><span class="n">cout</span> <span class="o">&lt;&lt;</span> <span class="s">&quot;Std =&gt;&quot;</span> <span class="o">&lt;&lt;</span> <span class="n">std</span><span class="o">::</span><span class="n">endl</span><span class="p">;</span> <span class="n">std</span><span class="o">::</span><span class="n">cout</span> <span class="o">&lt;&lt;</span> <span class="n">std</span><span class="o">::</span><span class="n">setprecision</span><span class="p">(</span><span class="n">std</span><span class="o">::</span><span class="n">numeric_limits</span><span class="o">&lt;</span><span class="kt">double</span><span class="o">&gt;::</span><span class="n">max_digits10</span><span class="p">);</span> <span class="n">std</span><span class="o">::</span><span class="n">cout</span> <span class="o">&lt;&lt;</span> <span class="s">&quot; Dividend: &quot;</span> <span class="o">&lt;&lt;</span> <span class="o">-</span><span class="n">d1</span> <span class="o">&lt;&lt;</span> <span class="n">std</span><span class="o">::</span><span class="n">endl</span><span class="p">;</span> <span class="n">std</span><span class="o">::</span><span class="n">cout</span> <span class="o">&lt;&lt;</span> <span class="s">&quot; Divisor : &quot;</span> <span class="o">&lt;&lt;</span> <span class="o">-</span><span class="n">d2</span> <span class="o">&lt;&lt;</span> <span class="n">std</span><span class="o">::</span><span class="n">endl</span><span class="p">;</span> <span class="n">std</span><span class="o">::</span><span class="n">cout</span> <span class="o">&lt;&lt;</span> <span class="s">&quot; Result : &quot;</span> <span class="o">&lt;&lt;</span> <span class="n">d3</span> <span class="o">&lt;&lt;</span> <span class="n">std</span><span class="o">::</span><span class="n">endl</span> <span class="o">&lt;&lt;</span> <span class="n">std</span><span class="o">::</span><span class="n">endl</span><span class="p">;</span> <span class="n">b3</span> <span class="o">=</span> <span class="n">boost</span><span class="o">::</span><span class="n">multiprecision</span><span class="o">::</span><span class="n">fmod</span><span class="p">(</span><span class="o">-</span><span class="n">b1</span><span class="p">,</span> <span class="n">b2</span><span class="p">);</span> <span class="n">d3</span> <span class="o">=</span> <span class="n">std</span><span class="o">::</span><span class="n">fmod</span><span class="p">(</span><span class="o">-</span><span class="n">d1</span><span class="p">,</span> <span class="n">d2</span><span class="p">);</span> <span class="n">std</span><span class="o">::</span><span class="n">cout</span> <span class="o">&lt;&lt;</span> <span class="s">&quot;Boost (Broken) =&gt;&quot;</span> <span class="o">&lt;&lt;</span> <span class="n">std</span><span class="o">::</span><span class="n">endl</span><span class="p">;</span> <span class="n">std</span><span class="o">::</span><span class="n">cout</span> <span class="o">&lt;&lt;</span> <span class="n">std</span><span class="o">::</span><span class="n">setprecision</span><span class="p">(</span><span class="n">std</span><span class="o">::</span><span class="n">numeric_limits</span><span class="o">&lt;</span><span class="n">boost</span><span class="o">::</span><span class="n">multiprecision</span><span class="o">::</span><span class="n">cpp_dec_float_100</span><span class="o">&gt;::</span><span class="n">max_digits10</span><span class="p">);</span> <span class="n">std</span><span class="o">::</span><span class="n">cout</span> <span class="o">&lt;&lt;</span> <span class="s">&quot; Dividend: &quot;</span> <span class="o">&lt;&lt;</span> <span class="o">-</span><span class="n">b1</span> <span class="o">&lt;&lt;</span> <span class="n">std</span><span class="o">::</span><span class="n">endl</span><span class="p">;</span> <span class="n">std</span><span class="o">::</span><span class="n">cout</span> <span class="o">&lt;&lt;</span> <span class="s">&quot; Divisor : &quot;</span> <span class="o">&lt;&lt;</span> <span class="n">b2</span> <span class="o">&lt;&lt;</span> <span class="n">std</span><span class="o">::</span><span class="n">endl</span><span class="p">;</span> <span class="n">std</span><span class="o">::</span><span class="n">cout</span> <span class="o">&lt;&lt;</span> <span class="s">&quot; Result : &quot;</span> <span class="o">&lt;&lt;</span> <span class="n">b3</span> <span class="o">&lt;&lt;</span> <span class="n">std</span><span class="o">::</span><span class="n">endl</span> <span class="o">&lt;&lt;</span> <span class="n">std</span><span class="o">::</span><span class="n">endl</span><span class="p">;</span> <span class="n">std</span><span class="o">::</span><span class="n">cout</span> <span class="o">&lt;&lt;</span> <span class="s">&quot;Std =&gt;&quot;</span> <span class="o">&lt;&lt;</span> <span class="n">std</span><span class="o">::</span><span class="n">endl</span><span class="p">;</span> <span class="n">std</span><span class="o">::</span><span class="n">cout</span> <span class="o">&lt;&lt;</span> <span class="n">std</span><span class="o">::</span><span class="n">setprecision</span><span class="p">(</span><span class="n">std</span><span class="o">::</span><span class="n">numeric_limits</span><span class="o">&lt;</span><span class="kt">double</span><span class="o">&gt;::</span><span class="n">max_digits10</span><span class="p">);</span> <span class="n">std</span><span class="o">::</span><span class="n">cout</span> <span class="o">&lt;&lt;</span> <span class="s">&quot; Dividend: &quot;</span> <span class="o">&lt;&lt;</span> <span class="o">-</span><span class="n">d1</span> <span class="o">&lt;&lt;</span> <span class="n">std</span><span class="o">::</span><span class="n">endl</span><span class="p">;</span> <span class="n">std</span><span class="o">::</span><span class="n">cout</span> <span class="o">&lt;&lt;</span> <span class="s">&quot; Divisor : &quot;</span> <span class="o">&lt;&lt;</span> <span class="n">d2</span> <span class="o">&lt;&lt;</span> <span class="n">std</span><span class="o">::</span><span class="n">endl</span><span class="p">;</span> <span class="n">std</span><span class="o">::</span><span class="n">cout</span> <span class="o">&lt;&lt;</span> <span class="s">&quot; Result : &quot;</span> <span class="o">&lt;&lt;</span> <span class="n">d3</span> <span class="o">&lt;&lt;</span> <span class="n">std</span><span class="o">::</span><span class="n">endl</span> <span class="o">&lt;&lt;</span> <span class="n">std</span><span class="o">::</span><span class="n">endl</span><span class="p">;</span> <span class="n">b3</span> <span class="o">=</span> <span class="n">boost</span><span class="o">::</span><span class="n">multiprecision</span><span class="o">::</span><span class="n">fmod</span><span class="p">(</span><span class="n">b1</span><span class="p">,</span> <span class="n">b2</span><span class="p">);</span> <span class="n">d3</span> <span class="o">=</span> <span class="n">std</span><span class="o">::</span><span class="n">fmod</span><span class="p">(</span><span class="n">d1</span><span class="p">,</span> <span class="n">d2</span><span class="p">);</span> <span class="n">std</span><span class="o">::</span><span class="n">cout</span> <span class="o">&lt;&lt;</span> <span class="s">&quot;Boost (Broken) =&gt;&quot;</span> <span class="o">&lt;&lt;</span> <span class="n">std</span><span class="o">::</span><span class="n">endl</span><span class="p">;</span> <span class="n">std</span><span class="o">::</span><span class="n">cout</span> <span class="o">&lt;&lt;</span> <span class="n">std</span><span class="o">::</span><span class="n">setprecision</span><span class="p">(</span><span class="n">std</span><span class="o">::</span><span class="n">numeric_limits</span><span class="o">&lt;</span><span class="n">boost</span><span class="o">::</span><span class="n">multiprecision</span><span class="o">::</span><span class="n">cpp_dec_float_100</span><span class="o">&gt;::</span><span class="n">max_digits10</span><span class="p">);</span> <span class="n">std</span><span class="o">::</span><span class="n">cout</span> <span class="o">&lt;&lt;</span> <span class="s">&quot; Dividend: &quot;</span> <span class="o">&lt;&lt;</span> <span class="n">b1</span> <span class="o">&lt;&lt;</span> <span class="n">std</span><span class="o">::</span><span class="n">endl</span><span class="p">;</span> <span class="n">std</span><span class="o">::</span><span class="n">cout</span> <span class="o">&lt;&lt;</span> <span class="s">&quot; Divisor : &quot;</span> <span class="o">&lt;&lt;</span> <span class="n">b2</span> <span class="o">&lt;&lt;</span> <span class="n">std</span><span class="o">::</span><span class="n">endl</span><span class="p">;</span> <span class="n">std</span><span class="o">::</span><span class="n">cout</span> <span class="o">&lt;&lt;</span> <span class="s">&quot; Result : &quot;</span> <span class="o">&lt;&lt;</span> <span class="n">b3</span> <span class="o">&lt;&lt;</span> <span class="n">std</span><span class="o">::</span><span class="n">endl</span> <span class="o">&lt;&lt;</span> <span class="n">std</span><span class="o">::</span><span class="n">endl</span><span class="p">;</span> <span class="n">std</span><span class="o">::</span><span class="n">cout</span> <span class="o">&lt;&lt;</span> <span class="s">&quot;Std =&gt;&quot;</span> <span class="o">&lt;&lt;</span> <span class="n">std</span><span class="o">::</span><span class="n">endl</span><span class="p">;</span> <span class="n">std</span><span class="o">::</span><span class="n">cout</span> <span class="o">&lt;&lt;</span> <span class="n">std</span><span class="o">::</span><span class="n">setprecision</span><span class="p">(</span><span class="n">std</span><span class="o">::</span><span class="n">numeric_limits</span><span class="o">&lt;</span><span class="kt">double</span><span class="o">&gt;::</span><span class="n">max_digits10</span><span class="p">);</span> <span class="n">std</span><span class="o">::</span><span class="n">cout</span> <span class="o">&lt;&lt;</span> <span class="s">&quot; Dividend: &quot;</span> <span class="o">&lt;&lt;</span> <span class="n">d1</span> <span class="o">&lt;&lt;</span> <span class="n">std</span><span class="o">::</span><span class="n">endl</span><span class="p">;</span> <span class="n">std</span><span class="o">::</span><span class="n">cout</span> <span class="o">&lt;&lt;</span> <span class="s">&quot; Divisor : &quot;</span> <span class="o">&lt;&lt;</span> <span class="n">d2</span> <span class="o">&lt;&lt;</span> <span class="n">std</span><span class="o">::</span><span class="n">endl</span><span class="p">;</span> <span class="n">std</span><span class="o">::</span><span class="n">cout</span> <span class="o">&lt;&lt;</span> <span class="s">&quot; Result : &quot;</span> <span class="o">&lt;&lt;</span> <span class="n">d3</span> <span class="o">&lt;&lt;</span> <span class="n">std</span><span class="o">::</span><span class="n">endl</span> <span class="o">&lt;&lt;</span> <span class="n">std</span><span class="o">::</span><span class="n">endl</span><span class="p">;</span> <span class="p">}</span> </pre></div></div><p> This outputs (on my system): </p> <p> -bash-4.1$ g++ -std=c++11 calc.cpp -o calc -bash-4.1$ ./calc </p> <p> Boost (Working) =&gt; </p> <blockquote> <p> Dividend: 5.5 Divisor : 3.333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333334 Result : 2.166666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666 </p> </blockquote> <p> Std =&gt; </p> <blockquote> <p> Dividend: 5.5 Divisor : 3.3333333333333335 Result : 2.1666666666666665 </p> </blockquote> <p> Boost (Working) =&gt; </p> <blockquote> <p> Dividend: -5.5 Divisor : 3.333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333334 Result : -2.166666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666 </p> </blockquote> <p> Std =&gt; </p> <blockquote> <p> Dividend: -5.5 Divisor : 3.3333333333333335 Result : -2.1666666666666665 </p> </blockquote> <p> Boost (Broken) =&gt; </p> <blockquote> <p> Dividend: -5.5 Divisor : -3.333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333334 Result : 1.166666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666668 </p> </blockquote> <p> Std =&gt; </p> <blockquote> <p> Dividend: -5.5 Divisor : -3.3333333333333335 Result : -2.1666666666666665 </p> </blockquote> <p> Boost (Broken) =&gt; </p> <blockquote> <p> Dividend: 5.5 Divisor : -3.333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333334 Result : -1.166666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666668 </p> </blockquote> <p> Std =&gt; </p> <blockquote> <p> Dividend: 5.5 Divisor : -3.3333333333333335 Result : 2.1666666666666665 </p> </blockquote> <p> I believe that the root cause is line 933 of include/boost/multiprecision/detail/default_ops.hpp (<a class="ext-link" href="https://github.com/boostorg/multiprecision/blob/master/include/boost/multiprecision/detail/default_ops.hpp"><span class="icon">​</span>https://github.com/boostorg/multiprecision/blob/master/include/boost/multiprecision/detail/default_ops.hpp</a>) </p> <p> Changing this from: </p> <div class="wiki-code"><div class="code"><pre> <span class="k">if</span><span class="p">(</span><span class="n">eval_get_sign</span><span class="p">(</span><span class="n">a</span><span class="p">)</span> <span class="o">&lt;</span> <span class="mi">0</span><span class="p">)</span> </pre></div></div><p> to </p> <div class="wiki-code"><div class="code"><pre> <span class="k">if</span><span class="p">(</span><span class="n">eval_get_sign</span><span class="p">(</span><span class="n">result</span><span class="p">)</span> <span class="o">&lt;</span> <span class="mi">0</span><span class="p">)</span> </pre></div></div><p> fixes the issue for this case, I'm currently trying to prepare a merge request but I didn't want to delay someone confirming that this is a issue that needs fixing or whether I have misunderstood something. </p> en-us Boost C++ Libraries /htdocs/site/boost.png https://svn.boost.org/trac10/ticket/11641 Trac 1.4.3 John Maddock Fri, 11 Sep 2015 16:00:55 GMT <link>https://svn.boost.org/trac10/ticket/11641#comment:1 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/11641#comment:1</guid> <description> <p> Thanks, confirmed. </p> <p> Testing patch and updated tests now, John. </p> </description> <category>Ticket</category> </item> <item> <dc:creator>John Maddock</dc:creator> <pubDate>Fri, 11 Sep 2015 17:25:51 GMT</pubDate> <title>status changed; resolution set https://svn.boost.org/trac10/ticket/11641#comment:2 https://svn.boost.org/trac10/ticket/11641#comment:2 <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> Fixed in <a class="ext-link" href="https://github.com/boostorg/multiprecision/commit/fdbeedc6090b44adeccc098381f2ddc890d6cf15"><span class="icon">​</span>https://github.com/boostorg/multiprecision/commit/fdbeedc6090b44adeccc098381f2ddc890d6cf15</a> </p> Ticket