Merge pull request #1815 from strk/2.1.x-too-many-float-digits
Use 15 significant digits for float to string conversion
This commit is contained in:
commit
855ff06159
3 changed files with 13 additions and 5 deletions
2
Makefile
2
Makefile
|
@ -25,7 +25,7 @@ test:
|
|||
@python tests/visual_tests/test.py -q || true
|
||||
@echo "*** Running C++ tests..."
|
||||
@for FILE in tests/cpp_tests/*-bin; do \
|
||||
$${FILE}; \
|
||||
$${FILE} || exit 1;\
|
||||
done
|
||||
@echo "*** Running python tests..."
|
||||
@python tests/run_tests.py -q
|
||||
|
|
|
@ -83,7 +83,7 @@ struct double_policy : boost::spirit::karma::real_policies<T>
|
|||
static unsigned precision(T n) {
|
||||
if ( n == 0.0 ) return 0;
|
||||
using namespace boost::spirit; // for traits
|
||||
return static_cast<unsigned>(15 - boost::math::trunc(log10(traits::get_absolute_value(n))));
|
||||
return static_cast<unsigned>(14 - boost::math::trunc(log10(traits::get_absolute_value(n))));
|
||||
}
|
||||
|
||||
template <typename OutputIterator>
|
||||
|
|
|
@ -82,14 +82,22 @@ int main( int, char*[] )
|
|||
BOOST_TEST_EQ( out, "-1000000000000000" );
|
||||
out.clear();
|
||||
|
||||
to_string(out, double(100000000000000.1));
|
||||
BOOST_TEST_EQ( out, "100000000000000.1" );
|
||||
to_string(out, double(10000000000000.1));
|
||||
BOOST_TEST_EQ( out, "10000000000000.1" );
|
||||
out.clear();
|
||||
|
||||
to_string(out, double(1.00001));
|
||||
BOOST_TEST_EQ( out, "1.00001" );
|
||||
out.clear();
|
||||
|
||||
|
||||
to_string(out, double(67.65));
|
||||
BOOST_TEST_EQ( out, "67.65" );
|
||||
out.clear();
|
||||
|
||||
to_string(out, double(67.35));
|
||||
BOOST_TEST_EQ( out, "67.35" );
|
||||
out.clear();
|
||||
|
||||
to_string(out, double(1234000000000000));
|
||||
BOOST_TEST_EQ( out, "1234000000000000" );
|
||||
out.clear();
|
||||
|
|
Loading…
Add table
Reference in a new issue