Opened 9 years ago

Closed 9 years ago

#8970 closed Bugs (fixed)

Karma fails to output a sign with a user-defined real number policy

Reported by: alex.korobka@… Owned by: Hartmut Kaiser
Milestone: To Be Determined Component: spirit
Version: Boost 1.54.0 Severity: Regression
Keywords: karma real Cc:

Description

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

Change History (2)

comment:1 by Joel de Guzman, 9 years ago

Owner: changed from Joel de Guzman to Hartmut Kaiser

comment:2 by Hartmut Kaiser, 9 years ago

Resolution: fixed
Status: newclosed

(In [85221]) Fixed #8970: Karma fails to output a sign with a user-defined real number policy

Note: See TracTickets for help on using tickets.