|
Boost-Commit : |
From: steven_at_[hidden]
Date: 2008-05-21 00:53:13
Author: steven_watanabe
Date: 2008-05-21 00:53:12 EDT (Wed, 21 May 2008)
New Revision: 45595
URL: http://svn.boost.org/trac/boost/changeset/45595
Log:
Added unit scaling and updated metric prefixes accordingly
Text files modified:
sandbox/units/boost/units/cmath.hpp | 4 +-
sandbox/units/boost/units/conversion.hpp | 2
sandbox/units/boost/units/detail/cmath_boost_1_35.hpp | 22 ++++++++--------
sandbox/units/boost/units/detail/conversion_impl.hpp | 31 +++++++++++++++-------
sandbox/units/boost/units/io.hpp | 6 +++
sandbox/units/boost/units/make_scaled_unit.hpp | 14 +++++++++
sandbox/units/boost/units/systems/si/prefixes.hpp | 55 +++++++++++++++++++++------------------
sandbox/units/libs/units/example/quaternion.cpp | 7 ++--
sandbox/units/libs/units/test/Jamfile.v2 | 4 +-
sandbox/units/libs/units/test/test_scaled_unit.cpp | 24 ++++++++++++++++
sandbox/units/libs/units/test_headers/Jamfile.v2 | 2
11 files changed, 111 insertions(+), 60 deletions(-)
Modified: sandbox/units/boost/units/cmath.hpp
==============================================================================
--- sandbox/units/boost/units/cmath.hpp (original)
+++ sandbox/units/boost/units/cmath.hpp 2008-05-21 00:53:12 EDT (Wed, 21 May 2008)
@@ -2,7 +2,7 @@
// unit/quantity manipulation and conversion
//
// Copyright (C) 2003-2008 Matthias Christian Schabel
-// Copyright (C) 2008 Steven Watanabe
+// Copyright (C) 2007-2008 Steven Watanabe
//
// Distributed under the Boost Software License, Version 1.0. (See
// accompanying file LICENSE_1_0.txt or copy at
@@ -14,7 +14,7 @@
#include <boost/version.hpp>
#if (BOOST_VERSION <= 103500)
- #include <boost/units/detail/cmath_boost_1_35.hpp>
+ #include <boost/units/detail/cmath_boost_1_35.hpp>
#else
#include <cmath>
Modified: sandbox/units/boost/units/conversion.hpp
==============================================================================
--- sandbox/units/boost/units/conversion.hpp (original)
+++ sandbox/units/boost/units/conversion.hpp 2008-05-21 00:53:12 EDT (Wed, 21 May 2008)
@@ -2,7 +2,7 @@
// unit/quantity manipulation and conversion
//
// Copyright (C) 2003-2008 Matthias Christian Schabel
-// Copyright (C) 2008 Steven Watanabe
+// Copyright (C) 2007-2008 Steven Watanabe
//
// Distributed under the Boost Software License, Version 1.0. (See
// accompanying file LICENSE_1_0.txt or copy at
Modified: sandbox/units/boost/units/detail/cmath_boost_1_35.hpp
==============================================================================
--- sandbox/units/boost/units/detail/cmath_boost_1_35.hpp (original)
+++ sandbox/units/boost/units/detail/cmath_boost_1_35.hpp 2008-05-21 00:53:12 EDT (Wed, 21 May 2008)
@@ -2,7 +2,7 @@
// unit/quantity manipulation and conversion
//
// Copyright (C) 2003-2008 Matthias Christian Schabel
-// Copyright (C) 2008 Steven Watanabe
+// Copyright (C) 2007-2008 Steven Watanabe
//
// Distributed under the Boost Software License, Version 1.0. (See
// accompanying file LICENSE_1_0.txt or copy at
@@ -521,7 +521,7 @@
typename dimensionless_quantity<si::system,Y>::type
cos(const quantity<si::plane_angle,Y>& theta)
{
- using std::cos;
+ using std::cos;
return cos(theta.value());
}
@@ -530,7 +530,7 @@
typename dimensionless_quantity<si::system,Y>::type
sin(const quantity<si::plane_angle,Y>& theta)
{
- using std::sin;
+ using std::sin;
return sin(theta.value());
}
@@ -539,7 +539,7 @@
typename dimensionless_quantity<si::system,Y>::type
tan(const quantity<si::plane_angle,Y>& theta)
{
- using std::tan;
+ using std::tan;
return tan(theta.value());
}
@@ -572,7 +572,7 @@
quantity<si::plane_angle,Y>
acos(const Y& val)
{
- using std::acos;
+ using std::acos;
return quantity<si::plane_angle,Y>(acos(val)*si::radians);
}
@@ -581,7 +581,7 @@
quantity<unit<plane_angle_dimension,System>,Y>
acos(const quantity<unit<dimensionless_type,System>,Y>& val)
{
- using std::acos;
+ using std::acos;
return quantity<unit<plane_angle_dimension,System>,Y>(acos(val)*si::radians);
}
@@ -590,7 +590,7 @@
quantity<si::plane_angle,Y>
asin(const Y& val)
{
- using std::asin;
+ using std::asin;
return quantity<si::plane_angle,Y>(asin(val)*si::radians);
}
@@ -599,7 +599,7 @@
quantity<unit<plane_angle_dimension,System>,Y>
asin(const quantity<unit<dimensionless_type,System>,Y>& val)
{
- using std::asin;
+ using std::asin;
return quantity<unit<plane_angle_dimension,System>,Y>(asin(val)*si::radians);
}
@@ -608,7 +608,7 @@
quantity<si::plane_angle,Y>
atan(const Y& val)
{
- using std::atan;
+ using std::atan;
return quantity<si::plane_angle,Y>(atan(val)*si::radians);
}
@@ -617,7 +617,7 @@
quantity<unit<plane_angle_dimension,System>,Y>
atan(const quantity<unit<dimensionless_type,System>,Y>& val)
{
- using std::atan;
+ using std::atan;
return quantity<unit<plane_angle_dimension,System>,Y>(atan(val)*si::radians);
}
@@ -626,7 +626,7 @@
quantity<si::plane_angle,Y>
atan2(const Y& y,const Y& x)
{
- using std::atan2;
+ using std::atan2;
return quantity<si::plane_angle,Y>(atan2(y,x)*si::radians);
}
Modified: sandbox/units/boost/units/detail/conversion_impl.hpp
==============================================================================
--- sandbox/units/boost/units/detail/conversion_impl.hpp (original)
+++ sandbox/units/boost/units/detail/conversion_impl.hpp 2008-05-21 00:53:12 EDT (Wed, 21 May 2008)
@@ -395,7 +395,8 @@
detail::conversion_impl<mpl::size<typename L1::type>::value>::template apply<
typename mpl::begin<typename L1::type>::type,
homogeneous_system<L2>
- >::value()
+ >::value() *
+ eval_scale_list<typename L1::scale>::value()
));
}
};
@@ -413,10 +414,12 @@
static destination_type convert(const quantity<unit<D, homogeneous_system<L1> >, T1>& source)
{
return(destination_type::from_value(source.value() /
- detail::conversion_impl<mpl::size<typename L2::type>::value>::template apply<
+ (detail::conversion_impl<mpl::size<typename L2::type>::value>::template apply<
typename mpl::begin<typename L2::type>::type,
homogeneous_system<L1>
- >::value()
+ >::value() *
+ eval_scale_list<typename L2::scale>::value()
+ )
));
}
};
@@ -443,13 +446,15 @@
>::type all_base_units;
/// INTERNAL ONLY
typedef typename detail::make_homogeneous_system<all_base_units>::type system;
+ /// INTERNAL ONLY
+ typedef typename mpl::divides<typename S1::scale, typename S2::scale>::type result_scale;
static destination_type convert(const source_type& source)
{
return(destination_type::from_value(source.value() *
(detail::conversion_impl<mpl::size<typename S1::type>::value>::template apply<
typename mpl::begin<typename S1::type>::type,
system
- >::value() /
+ >::value() * eval_scale_list<result_scale>::value() /
detail::conversion_impl<mpl::size<typename S2::type>::value>::template apply<
typename mpl::begin<typename S2::type>::type,
system
@@ -487,10 +492,11 @@
typename mpl::begin<typename L1::type>::type,
homogeneous_system<L2>
> impl;
- typedef typename impl::type type;
+ typedef eval_scale_list<typename L1::scale> scale;
+ typedef typename multiply_typeof_helper<typename impl::type, typename scale::type>::type type;
static type value()
{
- return(impl::value());
+ return(impl::value() * scale::value());
}
};
@@ -504,10 +510,11 @@
typename mpl::begin<typename L2::type>::type,
homogeneous_system<L1>
> impl;
- typedef typename impl::type type;
+ typedef eval_scale_list<typename L2::scale> scale;
+ typedef typename multiply_typeof_helper<typename impl::type, typename scale::type>::type type;
static type value()
{
- return(one() / impl::value());
+ return(one() / (impl::value() * scale::value()));
}
};
@@ -536,10 +543,14 @@
typename mpl::begin<typename S2::type>::type,
system
> conversion2;
- typedef typename divide_typeof_helper<typename conversion1::type, typename conversion2::type>::type type;
+ typedef eval_scale_list<typename mpl::divides<typename S1::scale, typename S2::scale>::type> scale;
+ typedef typename multiply_typeof_helper<
+ typename conversion1::type,
+ typename divide_typeof_helper<typename scale::type, typename conversion2::type>::type
+ >::type type;
static type value()
{
- return(conversion1::value() / conversion2::value());
+ return(conversion1::value() * (scale::value() / conversion2::value()));
}
};
Modified: sandbox/units/boost/units/io.hpp
==============================================================================
--- sandbox/units/boost/units/io.hpp (original)
+++ sandbox/units/boost/units/io.hpp 2008-05-21 00:53:12 EDT (Wed, 21 May 2008)
@@ -79,6 +79,9 @@
namespace detail {
+// This is needed so that std::string can be returned from
+// the base unit functions and wtill allow the operators
+// to work for any std::basic_ostream
template<class T>
const T& adapt_for_print(const T& t)
{
@@ -150,7 +153,8 @@
template<class Begin, class Os>
struct apply {
static void value(Os& os) {
- os << ' ' << mpl::deref<Begin>::type::base << '^' << mpl::deref<Begin>::type::exponent;
+ os << mpl::deref<Begin>::type::base << '^' << typename mpl::deref<Begin>::type::exponent() << ' ';
+ print_scale_impl<N - 1>::template apply<typename mpl::next<Begin>::type, Os>::value(os);
}
};
};
Modified: sandbox/units/boost/units/make_scaled_unit.hpp
==============================================================================
--- sandbox/units/boost/units/make_scaled_unit.hpp (original)
+++ sandbox/units/boost/units/make_scaled_unit.hpp 2008-05-21 00:53:12 EDT (Wed, 21 May 2008)
@@ -24,7 +24,19 @@
template<class Dimension, class UnitList, class OldScale, class Scale>
struct make_scaled_unit<unit<Dimension, heterogeneous_system<heterogeneous_system_impl<UnitList, Dimension, OldScale> > >, Scale> {
- typedef unit<Dimension, heterogeneous_system<heterogeneous_system_impl<UnitList, Dimension, typename mpl::times<OldScale, dimension_list<Scale, dimensionless_type> >::type> > > type;
+ typedef unit<
+ Dimension,
+ heterogeneous_system<
+ heterogeneous_system_impl<
+ UnitList,
+ Dimension,
+ typename mpl::times<
+ OldScale,
+ dimension_list<scale_list_dim<Scale>, dimensionless_type>
+ >::type
+ >
+ >
+ > type;
};
}
Modified: sandbox/units/boost/units/systems/si/prefixes.hpp
==============================================================================
--- sandbox/units/boost/units/systems/si/prefixes.hpp (original)
+++ sandbox/units/boost/units/systems/si/prefixes.hpp 2008-05-21 00:53:12 EDT (Wed, 21 May 2008)
@@ -13,38 +13,41 @@
#include <boost/units/static_constant.hpp>
+#include <boost/units/make_scaled_unit.hpp>
+#include <boost/units/systems/si/dimensionless.hpp>
+
namespace boost {
namespace units {
namespace si {
-//#define BOOST_UNITS_METRIC_PREFIX(exponent, name) \
-// typedef make_scaled_unit<dimensionless, scale<10, static_rational<exponent> > >::type name ## _type;\
-// BOOST_UNITS_STATIC_CONSTANT(name, name ## _type)
-//
-//BOOST_UNITS_METRIC_PREFIX(-24, yocto);
-//BOOST_UNITS_METRIC_PREFIX(-21, zepto);
-//BOOST_UNITS_METRIC_PREFIX(-18, atto);
-//BOOST_UNITS_METRIC_PREFIX(-15, femto);
-//BOOST_UNITS_METRIC_PREFIX(-12, pico);
-//BOOST_UNITS_METRIC_PREFIX(-9, nano);
-//BOOST_UNITS_METRIC_PREFIX(-6, micro);
-//BOOST_UNITS_METRIC_PREFIX(-3, milli);
-//BOOST_UNITS_METRIC_PREFIX(-2, centi);
-//BOOST_UNITS_METRIC_PREFIX(-1, deci);
-//BOOST_UNITS_METRIC_PREFIX(1, deka);
-//BOOST_UNITS_METRIC_PREFIX(2, hecto);
-//BOOST_UNITS_METRIC_PREFIX(3, kilo);
-//BOOST_UNITS_METRIC_PREFIX(6, mega);
-//BOOST_UNITS_METRIC_PREFIX(9, giga);
-//BOOST_UNITS_METRIC_PREFIX(12, tera);
-//BOOST_UNITS_METRIC_PREFIX(15, peta);
-//BOOST_UNITS_METRIC_PREFIX(18, exa);
-//BOOST_UNITS_METRIC_PREFIX(21, zetta);
-//BOOST_UNITS_METRIC_PREFIX(24, yotta);
+#define BOOST_UNITS_METRIC_PREFIX(exponent, name) \
+ typedef make_scaled_unit<dimensionless, scale<10, static_rational<exponent> > >::type name ## _type;\
+ BOOST_UNITS_STATIC_CONSTANT(name, name ## _type)
+
+BOOST_UNITS_METRIC_PREFIX(-24, yocto);
+BOOST_UNITS_METRIC_PREFIX(-21, zepto);
+BOOST_UNITS_METRIC_PREFIX(-18, atto);
+BOOST_UNITS_METRIC_PREFIX(-15, femto);
+BOOST_UNITS_METRIC_PREFIX(-12, pico);
+BOOST_UNITS_METRIC_PREFIX(-9, nano);
+BOOST_UNITS_METRIC_PREFIX(-6, micro);
+BOOST_UNITS_METRIC_PREFIX(-3, milli);
+BOOST_UNITS_METRIC_PREFIX(-2, centi);
+BOOST_UNITS_METRIC_PREFIX(-1, deci);
+BOOST_UNITS_METRIC_PREFIX(1, deka);
+BOOST_UNITS_METRIC_PREFIX(2, hecto);
+BOOST_UNITS_METRIC_PREFIX(3, kilo);
+BOOST_UNITS_METRIC_PREFIX(6, mega);
+BOOST_UNITS_METRIC_PREFIX(9, giga);
+BOOST_UNITS_METRIC_PREFIX(12, tera);
+BOOST_UNITS_METRIC_PREFIX(15, peta);
+BOOST_UNITS_METRIC_PREFIX(18, exa);
+BOOST_UNITS_METRIC_PREFIX(21, zetta);
+BOOST_UNITS_METRIC_PREFIX(24, yotta);
-BOOST_UNITS_STATIC_CONSTANT(yocto,long double) = (1e-24); ///< metric prefix for 1.0e-24
+/*BOOST_UNITS_STATIC_CONSTANT(yocto,long double) = (1e-24); ///< metric prefix for 1.0e-24
BOOST_UNITS_STATIC_CONSTANT(zepto,long double) = (1e-21); ///< metric prefix for 1.0e-21
BOOST_UNITS_STATIC_CONSTANT(atto,long double) = (1e-18); ///< metric prefix for 1.0e-18
BOOST_UNITS_STATIC_CONSTANT(femto,long double) = (1e-15); ///< metric prefix for 1.0e-15
@@ -63,7 +66,7 @@
BOOST_UNITS_STATIC_CONSTANT(peta,long double) = (1e15); ///< metric prefix for 1.0e+15
BOOST_UNITS_STATIC_CONSTANT(exa,long double) = (1e18); ///< metric prefix for 1.0e+18
BOOST_UNITS_STATIC_CONSTANT(zetta,long double) = (1e21); ///< metric prefix for 1.0e+21
-BOOST_UNITS_STATIC_CONSTANT(yotta,long double) = (1e24); ///< metric prefix for 1.0e+24
+BOOST_UNITS_STATIC_CONSTANT(yotta,long double) = (1e24); ///< metric prefix for 1.0e+24 */
} // namespace si
Modified: sandbox/units/libs/units/example/quaternion.cpp
==============================================================================
--- sandbox/units/libs/units/example/quaternion.cpp (original)
+++ sandbox/units/libs/units/example/quaternion.cpp 2008-05-21 00:53:12 EDT (Wed, 21 May 2008)
@@ -183,6 +183,7 @@
using boost::math::quaternion;
using namespace boost::units;
using namespace boost::units::test;
+ using boost::units::pow;
std::stringstream sstream1, sstream2;
@@ -199,8 +200,7 @@
<< "L-L = " << L-L << std::endl
<< "L*L = " << L*L << std::endl
<< "L/L = " << L/L << std::endl
- << "L^3 = " << pow<3>(L) << std::endl
- //<< "L^3 = " << boost::units::pow<3>(L) << std::endl // compiles if disambiguated
+ << "L^3 = " << boost::units::pow<3>(L) << std::endl // compiles if disambiguated
// << "L^(3/2) = " << pow< static_rational<3,2> >(L) << std::endl
// << "3vL = " << root<3>(L) << std::endl
// << "(3/2)vL = " << root< static_rational<3,2> >(L) << std::endl
@@ -220,8 +220,7 @@
<< "L-L = " << L-L << std::endl
// << "L*L = " << L*L << std::endl
// << "L/L = " << L/L << std::endl
- << "L^3 = " << pow<3>(L) << std::endl
-// << "L^3 = " << boost::units::pow<3>(L) << std::endl // compiles if disambiguated
+ << "L^3 = " << boost::units::pow<3>(L) << std::endl // compiles if disambiguated
// << "L^(3/2) = " << pow< static_rational<3,2> >(L) << std::endl
// << "3vL = " << root<3>(L) << std::endl
// << "(3/2)vL = " << root< static_rational<3,2> >(L) << std::endl
Modified: sandbox/units/libs/units/test/Jamfile.v2
==============================================================================
--- sandbox/units/libs/units/test/Jamfile.v2 (original)
+++ sandbox/units/libs/units/test/Jamfile.v2 2008-05-21 00:53:12 EDT (Wed, 21 May 2008)
@@ -20,7 +20,7 @@
import testing ;
-#alias test_framework : $(BOOST_ROOT)/libs/test/build//boost_unit_test_framework ;
+alias test_framework : $(BOOST_ROOT)/libs/test/build//boost_unit_test_framework ;
{
test-suite units
@@ -41,7 +41,7 @@
[ run test_limits.cpp : : : : ]
[ run test_custom_unit.cpp : : : : ]
[ run test_scaled_conversion.cpp : : : : ]
-# [ run test_scaled_unit.cpp test_framework : : : : ]
+ [ run test_scaled_unit.cpp test_framework : : : : ]
# [ run check_conversion_defs.cpp $(checklibs) : : : <dependency>$(check-conversion-dependencies) : ]
[ compile-fail fail_implicit_conversion.cpp : : ]
[ compile-fail fail_quantity_construct.cpp : : ]
Modified: sandbox/units/libs/units/test/test_scaled_unit.cpp
==============================================================================
--- sandbox/units/libs/units/test/test_scaled_unit.cpp (original)
+++ sandbox/units/libs/units/test/test_scaled_unit.cpp 2008-05-21 00:53:12 EDT (Wed, 21 May 2008)
@@ -29,16 +29,38 @@
#include <sstream>
#include <boost/test/unit_test.hpp>
+#include <boost/test/floating_point_comparison.hpp>
namespace bu = boost::units;
namespace si = boost::units::si;
-BOOST_AUTO_TEST_CASE(test_floating_point) {
+BOOST_AUTO_TEST_CASE(test_scaled_to_plain) {
bu::quantity<si::time> s1 = 12.5 * si::seconds;
bu::quantity<si::time> s2(si::nano * s1);
BOOST_CHECK_CLOSE_FRACTION(1e-9 * s1.value(), s2.value(), 0.000000001);
}
+BOOST_AUTO_TEST_CASE(test_plain_to_scaled) {
+ bu::quantity<si::time> s1 = 12.5 * si::seconds;
+ typedef bu::multiply_typeof_helper<si::nano_type, si::time>::type time_unit;
+ bu::quantity<time_unit> s2(s1);
+ BOOST_CHECK_CLOSE_FRACTION(1e9 * s1.value(), s2.value(), 0.000000001);
+}
+
+BOOST_AUTO_TEST_CASE(test_scaled_to_scaled) {
+ typedef bu::multiply_typeof_helper<si::mega_type, si::time>::type mega_time_unit;
+ typedef bu::multiply_typeof_helper<si::micro_type, si::time>::type micro_time_unit;
+ bu::quantity<mega_time_unit> s1(12.5 * si::seconds);
+ bu::quantity<micro_time_unit> s2(s1);
+ BOOST_CHECK_CLOSE_FRACTION(1e12 * s1.value(), s2.value(), 0.000000001);
+}
+
+BOOST_AUTO_TEST_CASE(test_conversion_factor) {
+ BOOST_CHECK_CLOSE_FRACTION(conversion_factor(si::nano*si::seconds, si::seconds), 1e-9, 0.000000001);
+ BOOST_CHECK_CLOSE_FRACTION(conversion_factor(si::seconds, si::nano*si::seconds), 1e9, 0.000000001);
+ BOOST_CHECK_CLOSE_FRACTION(conversion_factor(si::mega*si::seconds, si::micro*si::seconds), 1e12, 0.000000001);
+}
+
BOOST_AUTO_TEST_CASE(test_output) {
std::stringstream stream;
stream << si::nano * 12.5 * si::seconds;
Modified: sandbox/units/libs/units/test_headers/Jamfile.v2
==============================================================================
--- sandbox/units/libs/units/test_headers/Jamfile.v2 (original)
+++ sandbox/units/libs/units/test_headers/Jamfile.v2 2008-05-21 00:53:12 EDT (Wed, 21 May 2008)
@@ -20,7 +20,7 @@
headers = ;
rule setup ( ) {
- for local file in [ path.glob-tree ../../../boost/units : *.hpp ] {
+ for local file in [ path.glob-tree ../../../boost/units : *.hpp : cmath_*_impl*.hpp ] {
headers += $(file) ;
result += [ compile test.cpp : <define>BOOST_UNITS_HEADER_NAME=$(file) <dependency>$(file) : [ regex.replace [ path.relative-to ../../.. $(file) ] "/" "_" ] ] ;
Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk