[Boost-bugs] [Boost C++ Libraries] #8970: Karma fails to output a sign with a user-defined real number policy

Subject: [Boost-bugs] [Boost C++ Libraries] #8970: Karma fails to output a sign with a user-defined real number policy
From: Boost C++ Libraries (noreply_at_[hidden])
Date: 2013-08-05 23:49:48


#8970: Karma fails to output a sign with a user-defined real number policy
------------------------------+------------------------
 Reporter: alex.korobka@… | Owner: djowel
     Type: Bugs | Status: new
Milestone: To Be Determined | Component: spirit
  Version: Boost 1.54.0 | Severity: Regression
 Keywords: karma real |
------------------------------+------------------------
 Snippet that shows the problem:

 #include <iostream> \\
 #include <boost/spirit/include/karma.hpp> \\
 using namespace boost::spirit; \\
 template <typename Num> struct signed_policy : \\
 karma::real_policies<Num> {
     static bool force_sign(Num n) { return true; }
 }; \\
 int main() { \\
     std::string s; \\
     std::back_insert_iterator<std::string> sink(s); \\
     karma::generate(sink,
         karma::real_generator<double,signed_policy<double> >(), \\
         -0.123
     );
     std::cout << s << std::endl; \\
     return 0; \\
 }

 This prints " 0.123" instead of "-0.123".

 The problem is due to the recent argument change in integer_part() policy
 method.

         template <typename OutputIterator> \\
         static bool integer_part (OutputIterator& sink, T n, bool sign,
 bool force_sign)
         { \\
             return sign_inserter::call(sink,
                                        traits::test_zero(n), \\
                                        sign, force_sign) &&
                    int_inserter<10>::call(sink, n);
         }

 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).

-- 
Ticket URL: <https://svn.boost.org/trac/boost/ticket/8970>
Boost C++ Libraries <http://www.boost.org/>
Boost provides free peer-reviewed portable C++ source libraries.

This archive was generated by hypermail 2.1.7 : 2017-02-16 18:50:13 UTC