
| -----Original Message----- | From: boost-bounces@lists.boost.org | [mailto:boost-bounces@lists.boost.org] On Behalf Of Gennaro Prota | Sent: 02 August 2006 22:10 | To: boost@lists.boost.org | Subject: Re: [boost] Spurious warning in lexical_cast.hpp | | On Wed, 2 Aug 2006 20:35:19 +0100, "Paul A Bristow" | <pbristow@hetp.u-net.com> wrote: | | >| But...: are you serializing floating point values by means of | >| lexical_cast? | > | >No - I meant 'stringizing' | | Ok. It seems to me we need something along these lines (off | the top of | my head): | | #include "boost/limits.hpp" | | #define BOOST_is_ieee754(t) \ | typedef char required [ \ | std::numeric_limits<t>::is_iec559? 1 : -1 \ | ] /**/ | | | | template <typename T> | struct digits2 | { | enum { value = | std::numeric_limits<T>::digits }; | }; | | | template <typename T> | struct min_digits_10 | { | BOOST_is_ieee754(T); | | enum { value = | 30103 * (digits2<T>::value - 1) / 100000 }; | }; | | template <typename T> | struct max_digits_10 | { | BOOST_is_ieee754(T); | | enum { value = 2 + | 30103 * digits2<T>::value / 100000 | }; | } | | #undef BOOST_is_ieee754 This seems overcomplicated to me. the guaranteed 'minimum' digits are already defined by numeric_limits<>::digits10() (for float 6) and the next version of C++ will provide numeric_limits<>::max_digits10() (for float 9) so all we need to do is to use the stream.precision(2 + std::numeric_limits<Source>::digits * 301/1000); for the time being. If the type is not specialized, then it is not clear how many digits to use, so do nothing - will be the default 6 decimal digits so ... Moral - if you are providing a User defined Type, always specialize it for numeric_limits and provide a suitable value for digits, digits10 (and in future max_digits10). Paul --- Paul A Bristow Prizet Farmhouse, Kendal, Cumbria UK LA8 8AB +44 1539561830 & SMS, Mobile +44 7714 330204 & SMS pbristow@hetp.u-net.com