Set precision correctly for builtin and UDT floating types.

[SVN r35562]
This commit is contained in:
Alexander Nasonov
2006-10-11 19:43:54 +00:00
parent ee7ea0011c
commit 115ad05af5
2 changed files with 8 additions and 26 deletions

View File

@@ -5,8 +5,8 @@
// (See accompanying file LICENSE_1_0.txt // (See accompanying file LICENSE_1_0.txt
// or copy at http://www.boost.org/LICENSE_1_0.txt) // or copy at http://www.boost.org/LICENSE_1_0.txt)
#ifndef BOOST_DETAIL_LCAST_SET_PRECISION_HPP_INCLUDED #ifndef BOOST_DETAIL_LCAST_PRECISION_HPP_INCLUDED
#define BOOST_DETAIL_LCAST_SET_PRECISION_HPP_INCLUDED #define BOOST_DETAIL_LCAST_PRECISION_HPP_INCLUDED
#include <climits> #include <climits>
#include <ios> #include <ios>
@@ -28,7 +28,7 @@ namespace boost { namespace detail {
#ifdef _MSC_VER #ifdef _MSC_VER
#pragma warning (push) #pragma warning (push)
// conditional expression is constant (stream precision) // conditional expression is constant
#pragma warning (disable : 4127) #pragma warning (disable : 4127)
#endif #endif
@@ -85,7 +85,7 @@ inline std::streamsize lcast_get_precision()
// radix = 10 and digits10 == the number of decimal digits. // radix = 10 and digits10 == the number of decimal digits.
return 6; return 6;
} // template<class T> bool lcast_set_precision(std::ios_base& stream) }
template<class T> template<class T>
inline void lcast_set_precision(std::ios_base& stream) inline void lcast_set_precision(std::ios_base& stream)
@@ -109,5 +109,5 @@ inline void lcast_set_precision(std::ios_base& stream)
#undef BOOST_DETAIL_LCAST_ASSERT #undef BOOST_DETAIL_LCAST_ASSERT
#endif // BOOST_DETAIL_LCAST_SET_PRECISION_HPP_INCLUDED #endif // BOOST_DETAIL_LCAST_PRECISION_HPP_INCLUDED

View File

@@ -27,6 +27,7 @@
#include <boost/type_traits/is_pointer.hpp> #include <boost/type_traits/is_pointer.hpp>
#include <boost/call_traits.hpp> #include <boost/call_traits.hpp>
#include <boost/static_assert.hpp> #include <boost/static_assert.hpp>
#include <boost/detail/lcast_precision.hpp>
#ifdef BOOST_NO_STRINGSTREAM #ifdef BOOST_NO_STRINGSTREAM
#include <strstream> #include <strstream>
@@ -458,25 +459,7 @@ namespace boost
lexical_stream(char_type* = 0, char_type* = 0) lexical_stream(char_type* = 0, char_type* = 0)
{ {
stream.unsetf(std::ios::skipws); stream.unsetf(std::ios::skipws);
lcast_set_precision<Source, Target>(stream);
#if (defined _MSC_VER)
# pragma warning( push )
// conditional expression is constant
# pragma warning( disable : 4127 )
#endif
typedef std::numeric_limits<Target> t;
typedef std::numeric_limits<Source> s;
if(t::is_specialized)
stream.precision(1 + t::digits10);
else if(s::is_specialized)
stream.precision(1 + s::digits10);
#if (defined _MSC_VER)
# pragma warning( pop )
#endif
} }
~lexical_stream() ~lexical_stream()
{ {
@@ -626,8 +609,7 @@ namespace boost
typedef std::numeric_limits<InputStreamable> limits; typedef std::numeric_limits<InputStreamable> limits;
if(limits::is_specialized) lcast_set_precision<InputStreamable>(stream);
stream.precision(limits::digits10 + 1);
#if (defined _MSC_VER) #if (defined _MSC_VER)
# pragma warning( pop ) # pragma warning( pop )
#endif #endif