|
From: Matthias S. <mat...@us...> - 2007-04-05 21:08:55
|
Update of /cvsroot/boost-sandbox/boost-sandbox/boost/units/systems/si In directory sc8-pr-cvs3.sourceforge.net:/tmp/cvs-serv31276/systems/si Modified Files: codata_constants.hpp constants.hpp Log Message: remove measurement.hpp Index: constants.hpp =================================================================== RCS file: /cvsroot/boost-sandbox/boost-sandbox/boost/units/systems/si/constants.hpp,v retrieving revision 1.1.1.1 retrieving revision 1.2 diff -u -d -r1.1.1.1 -r1.2 --- constants.hpp 16 Mar 2007 18:12:45 -0000 1.1.1.1 +++ constants.hpp 5 Apr 2007 21:08:54 -0000 1.2 @@ -11,6 +11,99 @@ #ifndef BOOST_UNITS_CONSTANTS_HPP #define BOOST_UNITS_CONSTANTS_HPP +#include <cmath> +#include <iosfwd> +#include <iomanip> + +#include <boost/io/ios_state.hpp> + +namespace boost { + +namespace units { + +template<class Y> +class value_and_uncertainty +{ + public: + typedef value_and_uncertainty<Y> this_type; + typedef Y value_type; + + value_and_uncertainty(const value_type& val = value_type(), + const value_type& err = value_type()) : + value_(val), + uncertainty_(std::abs(err)) + { } + + value_and_uncertainty(const this_type& source) : + value_(source.value_), + uncertainty_(source.uncertainty_) + { } + + //~value_and_uncertainty() { } + + this_type& operator=(const this_type& source) + { + value_ = source.value_; + uncertainty_ = source.uncertainty_; + + return *this; + } + + operator value_type() const { return value_; } + + value_type value() const { return value_; } + value_type uncertainty() const { return uncertainty_; } + value_type lower_bound() const { return value_-uncertainty_; } + value_type upper_bound() const { return value_+uncertainty_; } + + private: + value_type value_, + uncertainty_; +}; + +// stream output +template<class Y> +inline +std::ostream& operator<<(std::ostream& os,const value_and_uncertainty<Y>& val) +{ + boost::io::ios_precision_saver precision_saver(os); + boost::io::ios_width_saver width_saver(os); + boost::io::ios_flags_saver flags_saver(os); + + os << std::setw(21); + + if (val.uncertainty() > Y(0)) + { + const Y relative_uncertainty = std::abs(val.uncertainty()/val.value()); + + const double exponent = std::log10(relative_uncertainty); + const long digits_of_precision = static_cast<long>(std::ceil(std::abs(exponent)))+3; + + // should try to replicate NIST CODATA syntax + os << std::setprecision(digits_of_precision) + //<< std::setw(digits_of_precision+8) + //<< std::scientific + << val.value(); +// << long(10*(relative_uncertainty/std::pow(Y(10),Y(exponent)))); + + os << " (rel. unc. = " + << std::setprecision(1) + << std::setw(7) + << std::scientific + << relative_uncertainty << ")"; + } + else + { + os << val.value() << " (exact)"; + } + + return os; +} + +} // namespace units + +} // namespace boost + #include <boost/units/systems/si/codata_constants.hpp> #endif // BOOST_UNITS_CONSTANTS_HPP Index: codata_constants.hpp =================================================================== RCS file: /cvsroot/boost-sandbox/boost-sandbox/boost/units/systems/si/codata_constants.hpp,v retrieving revision 1.3 retrieving revision 1.4 diff -u -d -r1.3 -r1.4 --- codata_constants.hpp 3 Apr 2007 23:14:00 -0000 1.3 +++ codata_constants.hpp 5 Apr 2007 21:08:54 -0000 1.4 @@ -25,7 +25,7 @@ namespace CODATA { -typedef dimensionless_quantity<SI::system,double>::type dimensionless_constant; +//typedef dimensionless_quantity<SI::system,double>::type dimensionless_constant; } // namespace CODATA |