#ifndef BOOST_NUMERIC_INTERVAL_IO_PRECISION_HPP #define BOOST_NUMERIC_INTERVAL_IO_PRECISION_HPP #include #include #include namespace boost { namespace numeric { template std::basic_ostream &operator<< (std::basic_ostream &stream,const interval &value) { const T abs_lower=value.lower()>=0 ? value.lower() : -value.lower(); const T abs_upper=value.upper()>=0 ? value.upper() : -value.upper(); const T lower_mantissa=value.lower()/std::pow(10,static_cast(std::log10(abs_lower)+0.5)); const T upper_mantissa=value.upper()/std::pow(10,static_cast(std::log10(abs_upper)+0.5)); const T difference=upper_mantissa-lower_mantissa; const double exponent=std::log10(difference); boost::io::ios_precision_saver state(stream,-exponent+0.5); return stream << (value.upper()+value.lower())/2; } } // namespace numeric } // namespace boost #endif // BOOST_NUMERIC_INTERVAL_IO_PRECISION_HPP