Ticket #9177: basic_text_oprimitive.hpp.2.patch

File basic_text_oprimitive.hpp.2.patch, 1.5 KB (added by John Maddock, 9 years ago)
  • basic_text_oprimitive.hpp

     
    136136    // we'll get a compile time error. This is meant to automatically
    137137    // support synthesized types which support floating point
    138138    // operations. Also it should handle compiler dependent types
    139     // such long double.  Due to John Maddoc.
     139    // such long double.  Due to John Maddock.
    140140
    141141    template<class T>
    142142    struct is_float {
     
    156156            boost::serialization::throw_exception(
    157157                archive_exception(archive_exception::output_stream_error)
    158158            );
     159#ifndef BOOST_NO_CXX11_NUMERIC_LIMITS
     160        const unsigned int digits = std::numeric_limits<T>::max_digits10;
     161#else
    159162        // The formulae for the number of decimla digits required is given in
    160163        // http://www2.open-std.org/JTC1/SC22/WG21/docs/papers/2005/n1822.pdf
    161164        // which is derived from Kahan's paper:
    162165        // http://http.cs.berkley.edu/~wkahan/ieee754status/ieee754.ps
    163         const unsigned int digits = (std::numeric_limits<float>::digits * 3010) / 10000;
    164         os << std::setprecision(digits);
     166        const unsigned int digits = std::numeric_limits<T>::radix == 2 ? (std::numeric_limits<T>::digits * 3010) / 10000 : std::numeric_limits<T>::digits10;
     167#endif
     168        os << std::setprecision(digits) << std::scientific;
    165169        os << t;
    166170    }
    167171