Boost C++ Libraries: Ticket #8970: Karma fails to output a sign with a user-defined real number policy https://svn.boost.org/trac10/ticket/8970 <p> Snippet that shows the problem: </p> <p> #include &lt;iostream&gt; <br /> #include &lt;boost/spirit/include/karma.hpp&gt; <br /> using namespace boost::spirit; <br /> template &lt;typename Num&gt; struct signed_policy : <br /> karma::real_policies&lt;Num&gt; { </p> <blockquote> <p> static bool force_sign(Num n) { return true; } </p> </blockquote> <p> }; <br /> int main() { <br /> </p> <blockquote> <p> std::string s; <br /> std::back_insert_iterator&lt;std::string&gt; sink(s); <br /> karma::generate(sink, </p> <blockquote> <p> karma::real_generator&lt;double,signed_policy&lt;double&gt; &gt;(), <br /> -0.123 </p> </blockquote> <p> ); std::cout &lt;&lt; s &lt;&lt; std::endl; <br /> return 0; <br /> </p> </blockquote> <p> } </p> <p> This prints " 0.123" instead of "-0.123". </p> <p> The problem is due to the recent argument change in integer_part() policy method. </p> <blockquote> <p> template &lt;typename <a class="missing wiki">OutputIterator</a>&gt; <br /> static bool integer_part (<a class="missing wiki">OutputIterator</a>&amp; sink, T n, bool sign, bool force_sign) { <br /> </p> <blockquote> <p> return sign_inserter::call(sink, </p> <blockquote> <p> traits::test_zero(n), <br /> sign, force_sign) &amp;&amp; </p> </blockquote> <p> int_inserter&lt;10&gt;::call(sink, n); </p> </blockquote> <p> } </p> </blockquote> <p> Argument 'T n' previously used to hold the entire floating point value. Now it holds only the integer part, hence the test_zero(n) is not sufficient anymore when the actual value is in the range of (-1 : 0) or (0, -1). </p> en-us Boost C++ Libraries /htdocs/site/boost.png https://svn.boost.org/trac10/ticket/8970 Trac 1.4.3 Joel de Guzman Tue, 06 Aug 2013 03:32:51 GMT owner changed https://svn.boost.org/trac10/ticket/8970#comment:1 https://svn.boost.org/trac10/ticket/8970#comment:1 <ul> <li><strong>owner</strong> changed from <span class="trac-author">Joel de Guzman</span> to <span class="trac-author">Hartmut Kaiser</span> </li> </ul> Ticket Hartmut Kaiser Tue, 06 Aug 2013 13:36:40 GMT status changed; resolution set https://svn.boost.org/trac10/ticket/8970#comment:2 https://svn.boost.org/trac10/ticket/8970#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> (In <a class="changeset" href="https://svn.boost.org/trac10/changeset/85221" title="Fixed #8970: Karma fails to output a sign with a user-defined real ...">[85221]</a>) Fixed <a class="closed ticket" href="https://svn.boost.org/trac10/ticket/8970" title="#8970: Bugs: Karma fails to output a sign with a user-defined real number policy (closed: fixed)">#8970</a>: Karma fails to output a sign with a user-defined real number policy </p> Ticket