|
Boost-Commit : |
From: steven_at_[hidden]
Date: 2008-01-19 17:35:36
Author: steven_watanabe
Date: 2008-01-19 17:35:35 EST (Sat, 19 Jan 2008)
New Revision: 42870
URL: http://svn.boost.org/trac/boost/changeset/42870
Log:
Reduced examples to 80 columns
Text files modified:
sandbox/units/libs/units/example/conversion.cpp | 22 ++-
sandbox/units/libs/units/example/conversion_factor.cpp | 24 +++
sandbox/units/libs/units/example/dimension.cpp | 37 +++++-
sandbox/units/libs/units/example/heterogeneous_unit.cpp | 14 +-
sandbox/units/libs/units/example/kitchen_sink.cpp | 37 ++++--
sandbox/units/libs/units/example/measurement.hpp | 52 ++-------
sandbox/units/libs/units/example/non_base_dimension.cpp | 7
sandbox/units/libs/units/example/performance.cpp | 201 ++++++++++++++++++++++++++++++++-------
sandbox/units/libs/units/example/quantity.cpp | 98 +++++++++++--------
sandbox/units/libs/units/example/quaternion.cpp | 76 ++++++++++----
sandbox/units/libs/units/example/radar_beam_height.cpp | 45 +++++---
sandbox/units/libs/units/example/runtime_conversion_factor.cpp | 14 ++
sandbox/units/libs/units/example/runtime_unit.cpp | 29 +++-
sandbox/units/libs/units/example/temperature.cpp | 31 +++--
sandbox/units/libs/units/example/test_system.hpp | 53 +++++++--
sandbox/units/libs/units/example/tutorial.cpp | 6
sandbox/units/libs/units/example/unit.cpp | 12 +
17 files changed, 504 insertions(+), 254 deletions(-)
Modified: sandbox/units/libs/units/example/conversion.cpp
==============================================================================
--- sandbox/units/libs/units/example/conversion.cpp (original)
+++ sandbox/units/libs/units/example/conversion.cpp 2008-01-19 17:35:35 EST (Sat, 19 Jan 2008)
@@ -78,21 +78,21 @@
{
// implicit value_type conversions
//[conversion_snippet_1
- quantity<SI::length> L1 = quantity<SI::length,int>(int(2.5)*SI::meters);
- quantity<SI::length,int> L2(quantity<SI::length,double>(2.5*SI::meters));
+ quantity<SI::length> L1 = quantity<SI::length,int>(int(2.5)*SI::meters);
+ quantity<SI::length,int> L2(quantity<SI::length,double>(2.5*SI::meters));
//]
//[conversion_snippet_3
- quantity<SI::length,int> L3 = static_cast<quantity<SI::length,int> >(L1);
+ quantity<SI::length,int> L3 = static_cast<quantity<SI::length,int> >(L1);
//]
//[conversion_snippet_4
- quantity<CGS::length> L4 = static_cast<quantity<CGS::length> >(L1);
+ quantity<CGS::length> L4 = static_cast<quantity<CGS::length> >(L1);
//]
- quantity<SI::length,int> L5(4*SI::meters),
- L6(5*SI::meters);
- quantity<CGS::length> L7(L1);
+ quantity<SI::length,int> L5(4*SI::meters),
+ L6(5*SI::meters);
+ quantity<CGS::length> L7(L1);
swap(L5,L6);
@@ -118,7 +118,7 @@
quantity<SI::energy> es2(ec);
quantity<SI::velocity> v1 = 2.0*SI::meters/SI::second,
- v2(quantity<CGS::velocity>(2.0*CGS::centimeters/CGS::second));
+ v2(2.0*CGS::centimeters/CGS::second);
//]
sstream1 << "volume (m^3) = " << vs << std::endl
@@ -218,14 +218,16 @@
if(str1.size() < str2.size())
{
- std::string::iterator iter = std::mismatch(str1.begin(), str1.end(), str2.begin()).first;
+ std::string::iterator iter =
+ std::mismatch(str1.begin(), str1.end(), str2.begin()).first;
std::cout << iter - str1.begin() << std::endl;
std::cout << std::count(str1.begin(), iter, '\n') << std::endl;
}
else
{
- std::string::iterator iter = std::mismatch(str2.begin(), str2.end(), str1.begin()).first;
+ std::string::iterator iter =
+ std::mismatch(str2.begin(), str2.end(), str1.begin()).first;
std::cout << iter - str2.begin() << std::endl;
std::cout << std::count(str2.begin(), iter, '\n') << std::endl;
Modified: sandbox/units/libs/units/example/conversion_factor.cpp
==============================================================================
--- sandbox/units/libs/units/example/conversion_factor.cpp (original)
+++ sandbox/units/libs/units/example/conversion_factor.cpp 2008-01-19 17:35:35 EST (Sat, 19 Jan 2008)
@@ -52,11 +52,25 @@
//[conversion_factor_snippet_1
- std::cout << conversion_factor<double>(CGS::dyne,SI::newton) << std::endl;
- std::cout << conversion_factor<double>(SI::newton/SI::kilogram,CGS::dyne/CGS::gram) << std::endl;
- std::cout << conversion_factor<double>(CGS::momentum(),SI::momentum()) << std::endl;
- std::cout << conversion_factor<double>(SI::momentum()/SI::mass(),CGS::momentum()/CGS::mass()) << std::endl;
- std::cout << conversion_factor<double>(CGS::gal,SI::meter_per_second_squared) << std::endl;
+ double dyne_to_newton =
+ conversion_factor(CGS::dyne,SI::newton);
+ std::cout << dyne_to_newton << std::endl;
+
+ double force_over_mass_conversion =
+ conversion_factor(SI::newton/SI::kilogram,CGS::dyne/CGS::gram);
+ std::cout << force_over_mass_conversion << std::endl;
+
+ double momentum_conversion =
+ conversion_factor(CGS::momentum(),SI::momentum());
+ std::cout << momentum_conversion << std::endl;
+
+ double momentum_over_mass_conversion =
+ conversion_factor(SI::momentum()/SI::mass(),CGS::momentum()/CGS::gram);
+ std::cout << momentum_over_mass_conversion << std::endl;
+
+ double acceleration_conversion =
+ conversion_factor(CGS::gal,SI::meter_per_second_squared);
+ std::cout << acceleration_conversion << std::endl;
//]
Modified: sandbox/units/libs/units/example/dimension.cpp
==============================================================================
--- sandbox/units/libs/units/example/dimension.cpp (original)
+++ sandbox/units/libs/units/example/dimension.cpp 2008-01-19 17:35:35 EST (Sat, 19 Jan 2008)
@@ -51,8 +51,20 @@
{
using namespace boost::units;
- BOOST_MPL_ASSERT((boost::is_same<length_dimension, mpl::push_front<dimensionless_type, dim<length_base_dimension, static_rational<1L, 1L> > >::type>));
- BOOST_MPL_ASSERT((boost::is_same<mass_dimension, mpl::push_front<dimensionless_type, dim<mass_base_dimension, static_rational<1L, 1L> > >::type>));
+ BOOST_MPL_ASSERT((boost::is_same<
+ length_dimension,
+ mpl::push_front<
+ dimensionless_type,
+ dim<length_base_dimension, static_rational<1L, 1L> >
+ >::type
+ >));
+ BOOST_MPL_ASSERT((boost::is_same<
+ mass_dimension,
+ mpl::push_front<
+ dimensionless_type,
+ dim<mass_base_dimension, static_rational<1L, 1L> >
+ >::type
+ >));
BOOST_MPL_ASSERT((boost::is_same<energy_dimension,
mpl::push_front<
mpl::push_front<
@@ -62,15 +74,22 @@
dim<mass_base_dimension, static_rational<1L, 1L> > >::type,
dim<length_base_dimension, static_rational<2L, 1L> > >::type>));
- std::cout << "length_dimension = " << simplify_typename(length_dimension()) << std::endl
- << "mass_dimension = " << simplify_typename(mass_dimension()) << std::endl
- << "time_dimension = " << simplify_typename(time_dimension()) << std::endl
- << "energy_dimension = " << simplify_typename(energy_dimension()) << std::endl;
+ std::cout << "length_dimension = "
+ << simplify_typename(length_dimension()) << std::endl
+ << "mass_dimension = "
+ << simplify_typename(mass_dimension()) << std::endl
+ << "time_dimension = "
+ << simplify_typename(time_dimension()) << std::endl
+ << "energy_dimension = "
+ << simplify_typename(energy_dimension()) << std::endl;
//[dimension_snippet_1
- typedef mpl::times<length_dimension,mass_dimension>::type LM_type;
- typedef mpl::divides<length_dimension,time_dimension>::type L_T_type;
- typedef static_root<mpl::divides<energy_dimension,mass_dimension>::type,static_rational<2> >::type V_type;
+ typedef mpl::times<length_dimension,mass_dimension>::type LM_type;
+ typedef mpl::divides<length_dimension,time_dimension>::type L_T_type;
+ typedef static_root<
+ mpl::divides<energy_dimension,mass_dimension>::type,
+ static_rational<2>
+ >::type V_type;
//]
BOOST_MPL_ASSERT((boost::is_same<LM_type,
Modified: sandbox/units/libs/units/example/heterogeneous_unit.cpp
==============================================================================
--- sandbox/units/libs/units/example/heterogeneous_unit.cpp (original)
+++ sandbox/units/libs/units/example/heterogeneous_unit.cpp 2008-01-19 17:35:35 EST (Sat, 19 Jan 2008)
@@ -68,12 +68,12 @@
<< std::endl;
sstream1 << 1.0*SI::meter*SI::kilogram/pow<2>(SI::second) << std::endl
- << 1.0*SI::meter*SI::kilogram/pow<2>(SI::second)/SI::meter << std::endl
- << std::endl;
+ << 1.0*SI::meter*SI::kilogram/pow<2>(SI::second)/SI::meter
+ << std::endl << std::endl;
sstream1 << 1.0*CGS::centimeter*SI::kilogram/pow<2>(SI::second) << std::endl
- << 1.0*CGS::centimeter*SI::kilogram/pow<2>(SI::second)/SI::meter << std::endl
- << std::endl;
+ << 1.0*CGS::centimeter*SI::kilogram/pow<2>(SI::second)/SI::meter
+ << std::endl << std::endl;
//]
//heterogeneous_unit_snippet_2
@@ -112,14 +112,16 @@
if(str1.size() < str2.size())
{
- std::string::iterator iter = std::mismatch(str1.begin(), str1.end(), str2.begin()).first;
+ std::string::iterator iter =
+ std::mismatch(str1.begin(), str1.end(), str2.begin()).first;
std::cout << iter - str1.begin() << std::endl;
std::cout << std::count(str1.begin(), iter, '\n') << std::endl;
}
else
{
- std::string::iterator iter = std::mismatch(str2.begin(), str2.end(), str1.begin()).first;
+ std::string::iterator iter =
+ std::mismatch(str2.begin(), str2.end(), str1.begin()).first;
std::cout << iter - str2.begin() << std::endl;
std::cout << std::count(str2.begin(), iter, '\n') << std::endl;
Modified: sandbox/units/libs/units/example/kitchen_sink.cpp
==============================================================================
--- sandbox/units/libs/units/example/kitchen_sink.cpp (original)
+++ sandbox/units/libs/units/example/kitchen_sink.cpp 2008-01-19 17:35:35 EST (Sat, 19 Jan 2008)
@@ -399,9 +399,9 @@
typedef std::complex<double> complex_type;
//[kitchen_sink_snippet_7
- quantity<electric_potential,complex_type> v = complex_type(12.5,0.0)*volts;
- quantity<current,complex_type> i = complex_type(3.0,4.0)*amperes;
- quantity<resistance,complex_type> z = complex_type(1.5,-2.0)*ohms;
+ quantity<electric_potential,complex_type> v = complex_type(12.5,0.0)*volts;
+ quantity<current,complex_type> i = complex_type(3.0,4.0)*amperes;
+ quantity<resistance,complex_type> z = complex_type(1.5,-2.0)*ohms;
//]
sstream1 << "V = " << v << std::endl
@@ -413,18 +413,19 @@
/// check quantities using user-defined type encapsulating error propagation
//[kitchen_sink_snippet_8
- quantity<length,measurement<double> > u(measurement<double>(1.0,0.0)*meters),
- w(measurement<double>(4.52,0.02)*meters),
- x(measurement<double>(2.0,0.2)*meters),
- y(measurement<double>(3.0,0.6)*meters);
+ quantity<length,measurement<double> >
+ u(measurement<double>(1.0,0.0)*meters),
+ w(measurement<double>(4.52,0.02)*meters),
+ x(measurement<double>(2.0,0.2)*meters),
+ y(measurement<double>(3.0,0.6)*meters);
//]
sstream1 << "x+y-w = " << x+y-w << std::endl
<< "w*x = " << w*x << std::endl
<< "x/y = " << x/y << std::endl
<< "w*y^2/(u*x)^2 = " << w*y*y/pow<2>(u*x) << std::endl
- << "w/(u*x)^(1/2) = " << w/pow< static_rational<1,2> >(u*x) << std::endl
- << std::endl;
+ << "w/(u*x)^(1/2) = " << w/pow< static_rational<1,2> >(u*x)
+ << std::endl << std::endl;
}
sstream2 << "S1 : 2" << std::endl;
@@ -495,13 +496,15 @@
sstream2 << "T = 310 K" << std::endl;
sstream2 << "n = " << 2.05835e-17 << " mol" << std::endl;
#if BOOST_UNITS_HAS_TYPEOF
- sstream2 << "R = 8.314472 m^2 kg s^-2 K^-1 mol^-1 (rel. unc. = " << 1.8e-6 << ")" << std::endl;
+ sstream2 << "R = 8.314472 m^2 kg s^-2 K^-1 mol^-1 (rel. unc. = "
+ << 1.8e-6 << ")" << std::endl;
#else
sstream2 << "no typeof" << std::endl;
#endif // BOOST_UNITS_HAS_TYPEOF
sstream2 << std::endl;
sstream2 << "theta = " << 0.375 << " rad" << std::endl;
- sstream2 << "sin(theta) = " << 0.366273 << " dimensionless" << std::endl;
+ sstream2 << "sin(theta) = " << 0.366273 << " dimensionless"
+ << std::endl;
sstream2 << "asin(sin(theta)) = " << 0.375 << " rad" << std::endl;
sstream2 << std::endl;
sstream2 << "V = (12.5,0) m^2 kg s^-3 A^-1" << std::endl;
@@ -513,9 +516,11 @@
sstream2 << "x+y-w = 0.48(+/-0.632772) m" << std::endl;
sstream2 << "w*x = 9.04(+/-0.904885) m^2" << std::endl;
- sstream2 << "x/y = 0.666667(+/-0.149071) dimensionless" << std::endl;
+ sstream2 << "x/y = 0.666667(+/-0.149071) dimensionless"
+ << std::endl;
sstream2 << "w*y^2/(u*x)^2 = 10.17(+/-3.52328) m^-1" << std::endl;
- sstream2 << "w/(u*x)^(1/2) = 3.19612(+/-0.160431) dimensionless" << std::endl;
+ sstream2 << "w/(u*x)^(1/2) = 3.19612(+/-0.160431) dimensionless"
+ << std::endl;
sstream2 << std::endl;
@@ -534,14 +539,16 @@
if(str1.size() < str2.size())
{
- std::string::iterator iter = std::mismatch(str1.begin(), str1.end(), str2.begin()).first;
+ std::string::iterator iter =
+ std::mismatch(str1.begin(), str1.end(), str2.begin()).first;
std::cout << iter - str1.begin() << std::endl;
std::cout << std::count(str1.begin(), iter, '\n') << std::endl;
}
else
{
- std::string::iterator iter = std::mismatch(str2.begin(), str2.end(), str1.begin()).first;
+ std::string::iterator iter =
+ std::mismatch(str2.begin(), str2.end(), str1.begin()).first;
std::cout << iter - str2.begin() << std::endl;
std::cout << std::count(str2.begin(), iter, '\n') << std::endl;
Modified: sandbox/units/libs/units/example/measurement.hpp
==============================================================================
--- sandbox/units/libs/units/example/measurement.hpp (original)
+++ sandbox/units/libs/units/example/measurement.hpp 2008-01-19 17:35:35 EST (Sat, 19 Jan 2008)
@@ -17,7 +17,6 @@
#include <iostream>
#include <boost/io/ios_state.hpp>
-//#include <boost/numeric/interval.hpp>
#include <boost/units/static_rational.hpp>
namespace boost {
@@ -40,7 +39,6 @@
public:
typedef measurement<Y> this_type;
typedef Y value_type;
-// typedef numeric::interval<value_type> interval_type;
measurement(const value_type& val = value_type(),
const value_type& err = value_type()) :
@@ -65,14 +63,12 @@
return *this;
}
- operator value_type() const { return value_; }
+ 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_; }
-
-// interval_type get_interval() const { return interval_type(lower_bound(),upper_bound()); }
+ 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_; }
this_type& operator+=(const value_type& val)
{
@@ -273,9 +269,11 @@
/// specialize power typeof helper
template<class Y,long N,long D>
-struct power_dimof_helper<measurement<Y>,static_rational<N,D> >
+struct power_dimof_helper<measurement<Y>,static_rational<N,D> >
{
- typedef measurement<typename power_dimof_helper<Y,static_rational<N,D> >::type> type;
+ typedef measurement<
+ typename power_dimof_helper<Y,static_rational<N,D> >::type
+ > type;
static type value(const measurement<Y>& x)
{
@@ -293,7 +291,9 @@
template<class Y,long N,long D>
struct root_typeof_helper<measurement<Y>,static_rational<N,D> >
{
- typedef measurement<typename root_typeof_helper<Y,static_rational<N,D> >::type> type;
+ typedef measurement<
+ typename root_typeof_helper<Y,static_rational<N,D> >::type
+ > type;
static type value(const measurement<Y>& x)
{
@@ -313,35 +313,7 @@
std::ostream& operator<<(std::ostream& os,const measurement<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)";
-// }
os << val.value() << "(+/-" << val.uncertainty() << ")";
Modified: sandbox/units/libs/units/example/non_base_dimension.cpp
==============================================================================
--- sandbox/units/libs/units/example/non_base_dimension.cpp (original)
+++ sandbox/units/libs/units/example/non_base_dimension.cpp 2008-01-19 17:35:35 EST (Sat, 19 Jan 2008)
@@ -41,7 +41,8 @@
//[non_base_dimension_snippet_1
-struct imperial_gallon_tag : base_unit<imperial_gallon_tag, volume_dimension, 1> { };
+struct imperial_gallon_tag :
+ base_unit<imperial_gallon_tag, volume_dimension, 1> { };
typedef make_system<imperial_gallon_tag>::type imperial;
@@ -71,7 +72,9 @@
} // namespace boost
-BOOST_UNITS_DEFINE_CONVERSION_FACTOR(boost::units::imperial_gallon_tag, boost::units::us_gallon_tag::unit_type, double, 1.2009499255);
+BOOST_UNITS_DEFINE_CONVERSION_FACTOR(boost::units::imperial_gallon_tag,
+ boost::units::us_gallon_tag::unit_type,
+ double, 1.2009499255);
using namespace boost::units;
Modified: sandbox/units/libs/units/example/performance.cpp
==============================================================================
--- sandbox/units/libs/units/example/performance.cpp (original)
+++ sandbox/units/libs/units/example/performance.cpp 2008-01-19 17:35:35 EST (Sat, 19 Jan 2008)
@@ -28,15 +28,30 @@
@endverbatim
**/
+
+#define _SCL_SECURE_NO_WARNINGS
+
#include <cstdlib>
#include <ctime>
#include <algorithm>
#include <iostream>
#include <iomanip>
+#include <boost/config.hpp>
#include <boost/timer.hpp>
#include <boost/utility/result_of.hpp>
+
+#ifdef BOOST_MSVC
+#pragma warning(push)
+#pragma warning(disable:4267; disable:4127; disable:4244; disable:4100)
+#endif
+
#include <boost/numeric/ublas/matrix.hpp>
+
+#ifdef BOOST_MSVC
+#pragma warning(pop)
+#endif
+
#include <boost/units/quantity.hpp>
#include <boost/units/systems/si.hpp>
#include <boost/units/cmath.hpp>
@@ -46,7 +61,13 @@
};
template<class T0, class T1, class Out>
-void tiled_multiply_carray_inner(T0* first, T1* second, Out* out, int totalwidth, int width2, int height1, int common) {
+void tiled_multiply_carray_inner(T0* first,
+ T1* second,
+ Out* out,
+ int totalwidth,
+ int width2,
+ int height1,
+ int common) {
for(int j = 0; j < height1; ++j) {
for(int i = 0; i < width2; ++i) {
Out value = out[j * totalwidth + i];
@@ -59,7 +80,12 @@
}
template<class T0, class T1, class Out>
-void tiled_multiply_carray_outer(T0* first, T1* second, Out* out, int width2, int height1, int common) {
+void tiled_multiply_carray_outer(T0* first,
+ T1* second,
+ Out* out,
+ int width2,
+ int height1,
+ int common) {
std::fill_n(out, width2 * height1, Out());
int j = 0;
for(; j < height1 - tile_block_size; j += tile_block_size) {
@@ -67,43 +93,98 @@
for(; i < width2 - tile_block_size; i += tile_block_size) {
int k = 0;
for(; k < common - tile_block_size; k += tile_block_size) {
- tiled_multiply_carray_inner(&first[k + width2 * j], &second[k * width2 + i], &out[j * width2 + i], width2, tile_block_size, tile_block_size, tile_block_size);
+ tiled_multiply_carray_inner(
+ &first[k + width2 * j],
+ &second[k * width2 + i],
+ &out[j * width2 + i],
+ width2,
+ tile_block_size,
+ tile_block_size,
+ tile_block_size);
}
- tiled_multiply_carray_inner(&first[k + width2 * j], &second[k * width2 + i], &out[j * width2 + i], width2, tile_block_size, tile_block_size, common - k);
+ tiled_multiply_carray_inner(
+ &first[k + width2 * j],
+ &second[k * width2 + i],
+ &out[j * width2 + i],
+ width2,
+ tile_block_size,
+ tile_block_size,
+ common - k);
}
int k = 0;
for(; k < common - tile_block_size; k += tile_block_size) {
- tiled_multiply_carray_inner(&first[k + width2 * j], &second[k * width2 + i], &out[j * width2 + i], width2, width2 - i, tile_block_size, tile_block_size);
- }
- tiled_multiply_carray_inner(&first[k + width2 * j], &second[k * width2 + i], &out[j * width2 + i], width2, width2 - i, tile_block_size, common - k);
+ tiled_multiply_carray_inner(
+ &first[k + width2 * j],
+ &second[k * width2 + i],
+ &out[j * width2 + i],
+ width2, width2 - i,
+ tile_block_size,
+ tile_block_size);
+ }
+ tiled_multiply_carray_inner(
+ &first[k + width2 * j],
+ &second[k * width2 + i],
+ &out[j * width2 + i],
+ width2, width2 - i,
+ tile_block_size,
+ common - k);
}
int i = 0;
for(; i < width2 - tile_block_size; i += tile_block_size) {
int k = 0;
for(; k < common - tile_block_size; k += tile_block_size) {
- tiled_multiply_carray_inner(&first[k + width2 * j], &second[k * width2 + i], &out[j * width2 + i], width2, tile_block_size, height1 - j, tile_block_size);
- }
- tiled_multiply_carray_inner(&first[k + width2 * j], &second[k * width2 + i], &out[j * width2 + i], width2, tile_block_size, height1 - j, common - k);
+ tiled_multiply_carray_inner(
+ &first[k + width2 * j],
+ &second[k * width2 + i],
+ &out[j * width2 + i],
+ width2,
+ tile_block_size,
+ height1 - j,
+ tile_block_size);
+ }
+ tiled_multiply_carray_inner(
+ &first[k + width2 * j],
+ &second[k * width2 + i],
+ &out[j * width2 + i],
+ width2,
+ tile_block_size,
+ height1 - j,
+ common - k);
}
int k = 0;
for(; k < common - tile_block_size; k += tile_block_size) {
- tiled_multiply_carray_inner(&first[k + width2 * j], &second[k * width2 + i], &out[j * width2 + i], width2, width2 - i, height1 - j, tile_block_size);
- }
- tiled_multiply_carray_inner(&first[k + width2 * j], &second[k * width2 + i], &out[j * width2 + i], width2, width2 - i, height1 - j, common - k);
+ tiled_multiply_carray_inner(
+ &first[k + width2 * j],
+ &second[k * width2 + i],
+ &out[j * width2 + i],
+ width2,
+ width2 - i,
+ height1 - j,
+ tile_block_size);
+ }
+ tiled_multiply_carray_inner(
+ &first[k + width2 * j],
+ &second[k * width2 + i],
+ &out[j * width2 + i],
+ width2,
+ width2 - i,
+ height1 - j,
+ common - k);
}
enum { max_value = 1000};
template<class F, class T, class N, class R>
R solve_differential_equation(F f, T lower, T upper, N steps, R start) {
+ typedef typename F::template result<T, R>::type f_result;
T h = (upper - lower) / (1.0*steps);
for(N i = N(); i < steps; ++i) {
R y = start;
T x = lower + h * (1.0*i);
- typename F::template result<T, R>::type k1 = f(x, y);
- typename F::template result<T, R>::type k2 = f(x + h / 2.0, y + h * k1 / 2.0);
- typename F::template result<T, R>::type k3 = f(x + h / 2.0, y + h * k2 / 2.0);
- typename F::template result<T, R>::type k4 = f(x + h, y + h * k3);
+ f_result k1 = f(x, y);
+ f_result k2 = f(x + h / 2.0, y + h * k1 / 2.0);
+ f_result k3 = f(x + h / 2.0, y + h * k2 / 2.0);
+ f_result k4 = f(x + h, y + h * k3);
start = y + h * (k1 + 2.0 * k2 + 2.0 * k3 + k4) / 6.0;
}
return(start);
@@ -120,10 +201,13 @@
}
boost::units::quantity<boost::units::SI::velocity>
- operator()(const quantity<SI::time>& x, const quantity<SI::length>& y) const {
+ operator()(const quantity<SI::time>& x,
+ const quantity<SI::length>& y) const {
using namespace boost::units;
using namespace SI;
- return(1.0 * meters / second - x * meters / pow<2>(seconds) + 4.0 * y / seconds );
+ return(1.0 * meters / second -
+ x * meters / pow<2>(seconds) +
+ 4.0 * y / seconds );
}
};
@@ -169,15 +253,19 @@
m2(i,j) = std::rand();
}
}
- std::cout << "multiplying ublas::matrix<double>(" << max_value << ", " << max_value << ") : ";
+ std::cout << "multiplying ublas::matrix<double>("
+ << max_value << ", " << max_value << ") : ";
boost::timer timer;
ublas_result = (prod(m1, m2));
std::cout << timer.elapsed() << " seconds" << std::endl;
}
- boost::numeric::ublas::matrix<boost::units::quantity<boost::units::SI::dimensionless> > ublas_resultq;
+ typedef boost::numeric::ublas::matrix<
+ boost::units::quantity<boost::units::SI::dimensionless>
+ > matrix_type;
+ matrix_type ublas_resultq;
{
- boost::numeric::ublas::matrix<boost::units::quantity<boost::units::SI::dimensionless> > m1(max_value, max_value);
- boost::numeric::ublas::matrix<boost::units::quantity<boost::units::SI::dimensionless> > m2(max_value, max_value);
+ matrix_type m1(max_value, max_value);
+ matrix_type m2(max_value, max_value);
std::srand(1492);
for(int i = 0; i < max_value; ++i) {
for(int j = 0; j < max_value; ++j) {
@@ -185,7 +273,8 @@
m2(i,j) = std::rand();
}
}
- std::cout << "multiplying ublas::matrix<quantity>(" << max_value << ", " << max_value << ") : ";
+ std::cout << "multiplying ublas::matrix<quantity>("
+ << max_value << ", " << max_value << ") : ";
boost::timer timer;
ublas_resultq = (prod(m1, m2));
std::cout << timer.elapsed() << " seconds" << std::endl;
@@ -199,30 +288,56 @@
m1[i] = std::rand();
m2[i] = std::rand();
}
- std::cout << "tiled_matrix_multiply<double>(" << max_value << ", " << max_value << ") : ";
+ std::cout << "tiled_matrix_multiply<double>("
+ << max_value << ", " << max_value << ") : ";
boost::timer timer;
- tiled_multiply_carray_outer(&m1[0], &m2[0], &cresult[0], max_value, max_value, max_value);
+ tiled_multiply_carray_outer(
+ &m1[0],
+ &m2[0],
+ &cresult[0],
+ max_value,
+ max_value,
+ max_value);
std::cout << timer.elapsed() << " seconds" << std::endl;
}
- std::vector<boost::units::quantity<boost::units::SI::energy> > cresultq(max_value * max_value);
+ std::vector<
+ boost::units::quantity<boost::units::SI::energy>
+ > cresultq(max_value * max_value);
{
- std::vector<boost::units::quantity<boost::units::SI::force> > m1(max_value * max_value);
- std::vector<boost::units::quantity<boost::units::SI::length> > m2(max_value * max_value);
+ std::vector<
+ boost::units::quantity<boost::units::SI::force>
+ > m1(max_value * max_value);
+ std::vector<
+ boost::units::quantity<boost::units::SI::length>
+ > m2(max_value * max_value);
std::srand(1492);
for(int i = 0; i < max_value * max_value; ++i) {
m1[i] = std::rand() * boost::units::SI::newtons;
m2[i] = std::rand() * boost::units::SI::meters;
}
- std::cout << "tiled_matrix_multiply<quantity>(" << max_value << ", " << max_value << ") : ";
+ std::cout << "tiled_matrix_multiply<quantity>("
+ << max_value << ", " << max_value << ") : ";
boost::timer timer;
- tiled_multiply_carray_outer(&m1[0], &m2[0], &cresultq[0], max_value, max_value, max_value);
+ tiled_multiply_carray_outer(
+ &m1[0],
+ &m2[0],
+ &cresultq[0],
+ max_value,
+ max_value,
+ max_value);
std::cout << timer.elapsed() << " seconds" << std::endl;
}
for(int i = 0; i < max_value; ++i) {
for(int j = 0; j < max_value; ++j) {
- if(std::abs(ublas_result(i,j) - cresult[i * max_value + j]) > ublas_result(i,j) /1e14) {
- std::cout << std::setprecision(15) << "Uh Oh. ublas_result(" << i << "," << j << ") = " << ublas_result(i,j) << std::endl
- << "cresult[" << i << " * " << max_value << " + " << j << "] = " << cresult[i * max_value + j] << std::endl;
+ double diff =
+ std::abs(ublas_result(i,j) - cresult[i * max_value + j]);
+ if(diff > ublas_result(i,j) /1e14) {
+ std::cout << std::setprecision(15) << "Uh Oh. ublas_result("
+ << i << "," << j << ") = " << ublas_result(i,j)
+ << std::endl
+ << "cresult[" << i << " * " << max_value << " + "
+ << j << "] = " << cresult[i * max_value + j]
+ << std::endl;
return(EXIT_FAILURE);
}
}
@@ -240,7 +355,9 @@
double x = .1 * i;
double value = 1.0/4.0 * x - 3.0/16.0 + 19.0/16.0 * std::exp(4 * x);
if(std::abs(values[i] - value) > value / 1e9) {
- std::cout << std::setprecision(15) << "i = : " << i << ", value = " << value << " approx = " << values[i] << std::endl;
+ std::cout << std::setprecision(15) << "i = : " << i
+ << ", value = " << value << " approx = " << values[i]
+ << std::endl;
return(EXIT_FAILURE);
}
}
@@ -253,14 +370,22 @@
boost::timer timer;
for(int i = 0; i < 1000; ++i) {
quantity<SI::time> x = .1 * i * seconds;
- values[i] = solve_differential_equation(f(), 0.0 * seconds, x, i * 100, 1.0 * meters);
+ values[i] = solve_differential_equation(
+ f(),
+ 0.0 * seconds,
+ x,
+ i * 100,
+ 1.0 * meters);
}
std::cout << timer.elapsed() << " seconds" << std::endl;
for(int i = 0; i < 1000; ++i) {
double x = .1 * i;
- quantity<SI::length> value = (1.0/4.0 * x - 3.0/16.0 + 19.0/16.0 * std::exp(4 * x)) * meters;
+ quantity<SI::length> value =
+ (1.0/4.0 * x - 3.0/16.0 + 19.0/16.0 * std::exp(4 * x)) * meters;
if(abs(values[i] - value) > value / 1e9) {
- std::cout << std::setprecision(15) << "i = : " << i << ", value = " << value << " approx = " << values[i] << std::endl;
+ std::cout << std::setprecision(15) << "i = : " << i
+ << ", value = " << value << " approx = "
+ << values[i] << std::endl;
return(EXIT_FAILURE);
}
}
Modified: sandbox/units/libs/units/example/quantity.cpp
==============================================================================
--- sandbox/units/libs/units/example/quantity.cpp (original)
+++ sandbox/units/libs/units/example/quantity.cpp 2008-01-19 17:35:35 EST (Sat, 19 Jan 2008)
@@ -75,8 +75,8 @@
{
//[quantity_snippet_1
- quantity<length> L = 2.0*meters; // quantity of length
- quantity<energy> E = kilograms*pow<2>(L/seconds); // quantity of energy
+ quantity<length> L = 2.0*meters; // quantity of length
+ quantity<energy> E = kilograms*pow<2>(L/seconds); // quantity of energy
//]
sstream1 << "L = " << L << std::endl
@@ -85,19 +85,25 @@
<< "L*L = " << L*L << std::endl
<< "L/L = " << L/L << std::endl
<< "L*meter = " << L*meter << std::endl
- << "kilograms*(L/seconds)*(L/seconds) = " << kilograms*(L/seconds)*(L/seconds) << std::endl
- << "kilograms*(L/seconds)^2 = " << kilograms*pow<2>(L/seconds) << std::endl
- << "L^3 = " << pow<3>(L) << std::endl
- << "L^(3/2) = " << pow<static_rational<3,2> >(L) << std::endl
- << "2vL = " << root<2>(L) << std::endl
- << "(3/2)vL = " << root<static_rational<3,2> >(L) << std::endl
+ << "kilograms*(L/seconds)*(L/seconds) = "
+ << kilograms*(L/seconds)*(L/seconds) << std::endl
+ << "kilograms*(L/seconds)^2 = "
+ << kilograms*pow<2>(L/seconds) << std::endl
+ << "L^3 = "
+ << pow<3>(L) << std::endl
+ << "L^(3/2) = "
+ << pow<static_rational<3,2> >(L) << std::endl
+ << "2vL = "
+ << root<2>(L) << std::endl
+ << "(3/2)vL = "
+ << root<static_rational<3,2> >(L) << std::endl
<< std::endl;
}
{
//[quantity_snippet_2
- quantity<length,std::complex<double> > L(std::complex<double>(3.0,4.0)*meters);
- quantity<energy,std::complex<double> > E(kilograms*pow<2>(L/seconds));
+ quantity<length,std::complex<double> > L(std::complex<double>(3.0,4.0)*meters);
+ quantity<energy,std::complex<double> > E(kilograms*pow<2>(L/seconds));
//]
sstream1 << "L = " << L << std::endl
@@ -106,40 +112,46 @@
<< "L*L = " << L*L << std::endl
<< "L/L = " << L/L << std::endl
<< "L*meter = " << L*meter << std::endl
- << "kilograms*(L/seconds)*(L/seconds) = " << kilograms*(L/seconds)*(L/seconds) << std::endl
- << "kilograms*(L/seconds)^2 = " << kilograms*pow<2>(L/seconds) << std::endl
- << "L^3 = " << pow<3>(L) << std::endl
- << "L^(3/2) = " << pow<static_rational<3,2> >(L) << std::endl
- << "2vL = " << root<2>(L) << std::endl
- << "(3/2)vL = " << root<static_rational<3,2> >(L) << std::endl
+ << "kilograms*(L/seconds)*(L/seconds) = "
+ << kilograms*(L/seconds)*(L/seconds) << std::endl
+ << "kilograms*(L/seconds)^2 = "
+ << kilograms*pow<2>(L/seconds) << std::endl
+ << "L^3 = "
+ << pow<3>(L) << std::endl
+ << "L^(3/2) = "
+ << pow<static_rational<3,2> >(L) << std::endl
+ << "2vL = "
+ << root<2>(L) << std::endl
+ << "(3/2)vL = "
+ << root<static_rational<3,2> >(L) << std::endl
<< std::endl;
}
- sstream2 << "L = 2 m" << std::endl
- << "L+L = 4 m" << std::endl
- << "L-L = 0 m" << std::endl
- << "L*L = 4 m^2" << std::endl
- << "L/L = 1 dimensionless" << std::endl
- << "L*meter = 2 m^2" << std::endl
- << "kilograms*(L/seconds)*(L/seconds) = 4 m^2 kg s^-2" << std::endl
- << "kilograms*(L/seconds)^2 = 4 m^2 kg s^-2" << std::endl
- << "L^3 = 8 m^3" << std::endl
- << "L^(3/2) = 2.82843 m^(3/2)" << std::endl
- << "2vL = 1.41421 m^(1/2)" << std::endl
- << "(3/2)vL = 1.5874 m^(2/3)" << std::endl
+ sstream2 << "L = 2 m\n"
+ << "L+L = 4 m\n"
+ << "L-L = 0 m\n"
+ << "L*L = 4 m^2\n"
+ << "L/L = 1 dimensionless\n"
+ << "L*meter = 2 m^2\n"
+ << "kilograms*(L/seconds)*(L/seconds) = 4 m^2 kg s^-2\n"
+ << "kilograms*(L/seconds)^2 = 4 m^2 kg s^-2\n"
+ << "L^3 = 8 m^3\n"
+ << "L^(3/2) = 2.82843 m^(3/2)\n"
+ << "2vL = 1.41421 m^(1/2)\n"
+ << "(3/2)vL = 1.5874 m^(2/3)\n"
<< std::endl
- << "L = (3,4) m" << std::endl
- << "L+L = (6,8) m" << std::endl
- << "L-L = (0,0) m" << std::endl
- << "L*L = (-7,24) m^2" << std::endl
- << "L/L = (1,0) dimensionless" << std::endl
- << "L*meter = (3,4) m^2" << std::endl
- << "kilograms*(L/seconds)*(L/seconds) = (-7,24) m^2 kg s^-2" << std::endl
- << "kilograms*(L/seconds)^2 = (-7,24) m^2 kg s^-2" << std::endl
- << "L^3 = (-117,44) m^3" << std::endl
- << "L^(3/2) = (2,11) m^(3/2)" << std::endl
- << "2vL = (2,1) m^(1/2)" << std::endl
- << "(3/2)vL = (2.38285,1.69466) m^(2/3)" << std::endl
+ << "L = (3,4) m\n"
+ << "L+L = (6,8) m\n"
+ << "L-L = (0,0) m\n"
+ << "L*L = (-7,24) m^2\n"
+ << "L/L = (1,0) dimensionless\n"
+ << "L*meter = (3,4) m^2\n"
+ << "kilograms*(L/seconds)*(L/seconds) = (-7,24) m^2 kg s^-2\n"
+ << "kilograms*(L/seconds)^2 = (-7,24) m^2 kg s^-2\n"
+ << "L^3 = (-117,44) m^3\n"
+ << "L^(3/2) = (2,11) m^(3/2)\n"
+ << "2vL = (2,1) m^(1/2)\n"
+ << "(3/2)vL = (2.38285,1.69466) m^(2/3)\n"
<< std::endl;
std::string str1(sstream1.str());
@@ -157,14 +169,16 @@
if(str1.size() < str2.size())
{
- std::string::iterator iter = std::mismatch(str1.begin(), str1.end(), str2.begin()).first;
+ std::string::iterator iter =
+ std::mismatch(str1.begin(), str1.end(), str2.begin()).first;
std::cout << iter - str1.begin() << std::endl;
std::cout << std::count(str1.begin(), iter, '\n') << std::endl;
}
else
{
- std::string::iterator iter = std::mismatch(str2.begin(), str2.end(), str1.begin()).first;
+ std::string::iterator iter =
+ std::mismatch(str2.begin(), str2.end(), str1.begin()).first;
std::cout << iter - str2.begin() << std::endl;
std::cout << std::count(str2.begin(), iter, '\n') << std::endl;
Modified: sandbox/units/libs/units/example/quaternion.cpp
==============================================================================
--- sandbox/units/libs/units/example/quaternion.cpp (original)
+++ sandbox/units/libs/units/example/quaternion.cpp 2008-01-19 17:35:35 EST (Sat, 19 Jan 2008)
@@ -68,12 +68,14 @@
//[quaternion_class_snippet_1
/// specialize power typeof helper
template<class Y,long N,long D>
-struct power_dimof_helper<boost::math::quaternion<Y>,static_rational<N,D> >
+struct power_dimof_helper<boost::math::quaternion<Y>,static_rational<N,D> >
{
// boost::math::quaternion only supports integer powers
BOOST_STATIC_ASSERT(D==1);
- typedef boost::math::quaternion<typename power_dimof_helper<Y,static_rational<N,D> >::type> type;
+ typedef boost::math::quaternion<
+ typename power_dimof_helper<Y,static_rational<N,D> >::type
+ > type;
static type value(const boost::math::quaternion<Y>& x)
{
@@ -83,12 +85,14 @@
/// specialize root typeof helper
template<class Y,long N,long D>
-struct root_typeof_helper<boost::math::quaternion<Y>,static_rational<N,D> >
+struct root_typeof_helper<boost::math::quaternion<Y>,static_rational<N,D> >
{
// boost::math::quaternion only supports integer powers
BOOST_STATIC_ASSERT(N==1);
- typedef boost::math::quaternion<typename root_typeof_helper<Y,static_rational<N,D> >::type> type;
+ typedef boost::math::quaternion<
+ typename root_typeof_helper<Y,static_rational<N,D> >::type
+ > type;
static type value(const boost::math::quaternion<Y>& x)
{
@@ -100,20 +104,31 @@
//[quaternion_class_snippet_2
/// specialize power typeof helper for quaternion<quantity<Unit,Y> >
template<class Unit,long N,long D,class Y>
-struct power_dimof_helper<boost::math::quaternion<quantity<Unit,Y> >,static_rational<N,D> >
+struct power_dimof_helper<
+ boost::math::quaternion<quantity<Unit,Y> >,
+ static_rational<N,D> >
{
- typedef typename power_dimof_helper<Y,static_rational<N,D> >::type value_type;
- typedef typename power_dimof_helper<Unit,static_rational<N,D> >::type unit_type;
- typedef quantity<unit_type,value_type> quantity_type;
- typedef boost::math::quaternion<quantity_type> type;
+ typedef typename power_dimof_helper<
+ Y,
+ static_rational<N,D>
+ >::type value_type;
+
+ typedef typename power_dimof_helper<
+ Unit,
+ static_rational<N,D>
+ >::type unit_type;
+
+ typedef quantity<unit_type,value_type> quantity_type;
+ typedef boost::math::quaternion<quantity_type> type;
static type value(const boost::math::quaternion<quantity<Unit,Y> >& x)
{
const boost::math::quaternion<value_type> tmp =
- pow<static_rational<N,D> >(boost::math::quaternion<Y>(x.R_component_1().value(),
- x.R_component_2().value(),
- x.R_component_3().value(),
- x.R_component_4().value()));
+ pow<static_rational<N,D> >(boost::math::quaternion<Y>(
+ x.R_component_1().value(),
+ x.R_component_2().value(),
+ x.R_component_3().value(),
+ x.R_component_4().value()));
return type(quantity_type::from_value(tmp.R_component_1()),
quantity_type::from_value(tmp.R_component_2()),
@@ -124,20 +139,31 @@
/// specialize root typeof helper for quaternion<quantity<Unit,Y> >
template<class Unit,long N,long D,class Y>
-struct root_typeof_helper<boost::math::quaternion<quantity<Unit,Y> >,static_rational<N,D> >
+struct root_typeof_helper<
+ boost::math::quaternion<quantity<Unit,Y> >,
+ static_rational<N,D> >
{
- typedef typename root_typeof_helper<Y,static_rational<N,D> >::type value_type;
- typedef typename root_typeof_helper<Unit,static_rational<N,D> >::type unit_type;
- typedef quantity<unit_type,value_type> quantity_type;
- typedef boost::math::quaternion<quantity_type> type;
+ typedef typename root_typeof_helper<
+ Y,
+ static_rational<N,D>
+ >::type value_type;
+
+ typedef typename root_typeof_helper<
+ Unit,
+ static_rational<N,D>
+ >::type unit_type;
+
+ typedef quantity<unit_type,value_type> quantity_type;
+ typedef boost::math::quaternion<quantity_type> type;
static type value(const boost::math::quaternion<quantity<Unit,Y> >& x)
{
const boost::math::quaternion<value_type> tmp =
- root<static_rational<N,D> >(boost::math::quaternion<Y>(x.R_component_1().value(),
- x.R_component_2().value(),
- x.R_component_3().value(),
- x.R_component_4().value()));
+ root<static_rational<N,D> >(boost::math::quaternion<Y>(
+ x.R_component_1().value(),
+ x.R_component_2().value(),
+ x.R_component_3().value(),
+ x.R_component_4().value()));
return type(quantity_type::from_value(tmp.R_component_1()),
quantity_type::from_value(tmp.R_component_2()),
@@ -229,14 +255,16 @@
if(str1.size() < str2.size())
{
- std::string::iterator iter = std::mismatch(str1.begin(), str1.end(), str2.begin()).first;
+ std::string::iterator iter =
+ std::mismatch(str1.begin(), str1.end(), str2.begin()).first;
std::cout << iter - str1.begin() << std::endl;
std::cout << std::count(str1.begin(), iter, '\n') << std::endl;
}
else
{
- std::string::iterator iter = std::mismatch(str2.begin(), str2.end(), str1.begin()).first;
+ std::string::iterator iter =
+ std::mismatch(str2.begin(), str2.end(), str1.begin()).first;
std::cout << iter - str2.begin() << std::endl;
std::cout << std::count(str2.begin(), iter, '\n') << std::endl;
Modified: sandbox/units/libs/units/example/radar_beam_height.cpp
==============================================================================
--- sandbox/units/libs/units/example/radar_beam_height.cpp (original)
+++ sandbox/units/libs/units/example/radar_beam_height.cpp 2008-01-19 17:35:35 EST (Sat, 19 Jan 2008)
@@ -70,7 +70,9 @@
} // namespace boost
-BOOST_UNITS_DEFINE_CONVERSION_FACTOR(boost::units::nautical::length_base_unit, boost::units::meter_base_unit::unit_type, double, 1.852e3);
+BOOST_UNITS_DEFINE_CONVERSION_FACTOR(boost::units::nautical::length_base_unit,
+ boost::units::meter_base_unit::unit_type,
+ double, 1.852e3);
namespace boost {
@@ -100,7 +102,9 @@
} // namespace boost
-BOOST_UNITS_DEFINE_CONVERSION_FACTOR(boost::units::imperial::length_base_unit, boost::units::meter_base_unit::unit_type, double, 1.0/3.28083989501312);
+BOOST_UNITS_DEFINE_CONVERSION_FACTOR(boost::units::imperial::length_base_unit,
+ boost::units::meter_base_unit::unit_type,
+ double, 1.0/3.28083989501312);
namespace boost {
@@ -116,7 +120,8 @@
const quantity<unit<length_dimension,System>,T>& earth_radius,
T k = 4.0/3.0)
{
- return quantity<unit<length_dimension,System>,T>(pow<2>(radar_range)/(2.0*k*earth_radius));
+ return quantity<unit<length_dimension,System>,T>(
+ pow<2>(radar_range)/(2.0*k*earth_radius));
}
//]
@@ -124,7 +129,7 @@
template<class return_type,class System1,class System2,typename T>
return_type
radar_beam_height(const quantity<unit<length_dimension,System1>,T>& radar_range,
- const quantity<unit<length_dimension,System2>,T>& earth_radius,
+ const quantity<unit<length_dimension,System2>,T>& earth_radius,
T k = 4.0/3.0)
{
// need to decide which system to use for calculation
@@ -136,9 +141,11 @@
//]
//[radar_beam_height_function_snippet_3
-quantity<imperial::length> radar_beam_height(const quantity<nautical::length>& range)
+quantity<imperial::length>
+radar_beam_height(const quantity<nautical::length>& range)
{
- return quantity<imperial::length>(pow<2>(range/(1.23*nautical::miles/root<2>(imperial::feet))));
+ return quantity<imperial::length>(
+ pow<2>(range/(1.23*nautical::miles/root<2>(imperial::feet))));
}
//]
@@ -155,13 +162,13 @@
std::stringstream sstream1, sstream2;
//[radar_beam_height_snippet_1
- const quantity<nautical::length> radar_range(300.0*miles);
- const quantity<SI::length> earth_radius(6371.0087714*kilo*meters);
+ const quantity<nautical::length> radar_range(300.0*miles);
+ const quantity<SI::length> earth_radius(6371.0087714*kilo*meters);
- const quantity<SI::length> beam_height_1(radar_beam_height(quantity<SI::length>(radar_range),earth_radius));
- const quantity<nautical::length> beam_height_2(radar_beam_height(radar_range,quantity<nautical::length>(earth_radius)));
- const quantity<SI::length> beam_height_3(radar_beam_height< quantity<SI::length> >(radar_range,earth_radius));
- const quantity<nautical::length> beam_height_4(radar_beam_height< quantity<nautical::length> >(radar_range,earth_radius));
+ const quantity<SI::length> beam_height_1(radar_beam_height(quantity<SI::length>(radar_range),earth_radius));
+ const quantity<nautical::length> beam_height_2(radar_beam_height(radar_range,quantity<nautical::length>(earth_radius)));
+ const quantity<SI::length> beam_height_3(radar_beam_height< quantity<SI::length> >(radar_range,earth_radius));
+ const quantity<nautical::length> beam_height_4(radar_beam_height< quantity<nautical::length> >(radar_range,earth_radius));
//]
sstream1 << "radar range : " << radar_range << std::endl
@@ -170,9 +177,11 @@
<< "beam height 2 : " << beam_height_2 << std::endl
<< "beam height 3 : " << beam_height_3 << std::endl
<< "beam height 4 : " << beam_height_4 << std::endl
- << "beam height approx : " << radar_beam_height(radar_range) << std::endl
- << "beam height approx : " << quantity<SI::length>(radar_beam_height(radar_range)) << std::endl
- << std::endl;
+ << "beam height approx : " << radar_beam_height(radar_range)
+ << std::endl
+ << "beam height approx : "
+ << quantity<SI::length>(radar_beam_height(radar_range))
+ << std::endl << std::endl;
sstream2 << "radar range : 300 nmi" << std::endl;
sstream2 << "earth radius : " << 6.37101e6 << " m" << std::endl;
@@ -199,14 +208,16 @@
if(str1.size() < str2.size())
{
- std::string::iterator iter = std::mismatch(str1.begin(), str1.end(), str2.begin()).first;
+ std::string::iterator iter =
+ std::mismatch(str1.begin(), str1.end(), str2.begin()).first;
std::cout << iter - str1.begin() << std::endl;
std::cout << std::count(str1.begin(), iter, '\n') << std::endl;
}
else
{
- std::string::iterator iter = std::mismatch(str2.begin(), str2.end(), str1.begin()).first;
+ std::string::iterator iter =
+ std::mismatch(str2.begin(), str2.end(), str1.begin()).first;
std::cout << iter - str2.begin() << std::endl;
std::cout << std::count(str2.begin(), iter, '\n') << std::endl;
Modified: sandbox/units/libs/units/example/runtime_conversion_factor.cpp
==============================================================================
--- sandbox/units/libs/units/example/runtime_conversion_factor.cpp (original)
+++ sandbox/units/libs/units/example/runtime_conversion_factor.cpp 2008-01-19 17:35:35 EST (Sat, 19 Jan 2008)
@@ -15,14 +15,18 @@
//[runtime_conversion_factor_snippet_1
+using boost::units::base_dimension;
+using boost::units::base_unit;
+
static const long currency_base = 1;
-struct currency_base_dimension : boost::units::base_dimension<currency_base_dimension, 1> {};
+struct currency_base_dimension : base_dimension<currency_base_dimension, 1> {};
typedef currency_base_dimension::dimension_type currency_type;
template<long N>
-struct currency_base_unit : boost::units::base_unit<currency_base_unit<N>, currency_type, currency_base + N> {};
+struct currency_base_unit :
+ base_unit<currency_base_unit<N>, currency_type, currency_base + N> {};
typedef currency_base_unit<0> us_dollar_base_unit;
typedef currency_base_unit<1> euro_base_unit;
@@ -45,7 +49,11 @@
conversion_factors[to][from] = 1.0 / value;
}
-BOOST_UNITS_DEFINE_BASE_CONVERSION_TEMPLATE((long N1)(long N2), currency_base_unit<N1>, currency_base_unit<N2>, double, get_conversion_factor(N1, N2));
+BOOST_UNITS_DEFINE_BASE_CONVERSION_TEMPLATE((long N1)(long N2),
+ currency_base_unit<N1>,
+ currency_base_unit<N2>,
+ double,
+ get_conversion_factor(N1, N2));
//]
Modified: sandbox/units/libs/units/example/runtime_unit.cpp
==============================================================================
--- sandbox/units/libs/units/example/runtime_unit.cpp (original)
+++ sandbox/units/libs/units/example/runtime_unit.cpp 2008-01-19 17:35:35 EST (Sat, 19 Jan 2008)
@@ -20,18 +20,21 @@
namespace {
-std::map<std::string, boost::units::quantity<boost::units::SI::length> > known_units;
+using namespace boost::units;
+
+std::map<std::string, quantity<SI::length> > known_units;
}
-boost::units::quantity<boost::units::SI::length> calculate(const boost::units::quantity<boost::units::SI::length>& t) {
- return(boost::units::hypot(t, 2.0 * boost::units::SI::meters));
+quantity<SI::length> calculate(const quantity<SI::length>& t) {
+ return(boost::units::hypot(t, 2.0 * SI::meters));
}
int main() {
- known_units["meter"] = 1.0 * boost::units::SI::meters;
- known_units["centimeter"] = .01 * boost::units::SI::meters;;
- known_units["foot"] = conversion_factor(boost::units::foot_base_unit::unit_type(), boost::units::SI::meter) * boost::units::SI::meters;;
+ known_units["meter"] = 1.0 * SI::meters;
+ known_units["centimeter"] = .01 * SI::meters;;
+ known_units["foot"] =
+ conversion_factor(foot_base_unit::unit_type(), SI::meter) * SI::meter;
std::string output_type("meter");
std::string input;
while((std::cout << ">") && (std::cin >> input)) {
@@ -39,14 +42,16 @@
else if(input == "help") {
std::cout << "type \"exit\" to exit\n"
"type \"return 'unit'\" to set the return units\n"
- "type \"'number' 'unit'\" to do a simple calculation" << std::endl;
+ "type \"'number' 'unit'\" to do a simple calculation"
+ << std::endl;
} else if(input == "return") {
if(std::cin >> input) {
if(known_units.find(input) != known_units.end()) {
output_type = input;
std::cout << "Done." << std::endl;
} else {
- std::cout << "Unknown unit \"" << input << "\"" << std::endl;
+ std::cout << "Unknown unit \"" << input << "\""
+ << std::endl;
}
} else break;
} else {
@@ -54,9 +59,13 @@
double value = boost::lexical_cast<double>(input);
if(std::cin >> input) {
if(known_units.find(input) != known_units.end()) {
- std::cout << static_cast<double>(calculate(value * known_units[input]) / known_units[output_type]) << ' ' << output_type << std::endl;
+ std::cout << static_cast<double>(
+ calculate(value * known_units[input]) /
+ known_units[output_type])
+ << ' ' << output_type << std::endl;
} else {
- std::cout << "Unknown unit \"" << input << "\"" << std::endl;
+ std::cout << "Unknown unit \"" << input << "\""
+ << std::endl;
}
} else break;
} catch(...) {
Modified: sandbox/units/libs/units/example/temperature.cpp
==============================================================================
--- sandbox/units/libs/units/example/temperature.cpp (original)
+++ sandbox/units/libs/units/example/temperature.cpp 2008-01-19 17:35:35 EST (Sat, 19 Jan 2008)
@@ -67,14 +67,15 @@
//[temperature_snippet_2
template<>
-struct is_implicitly_convertible< unit<temperature_dimension,fahrenheit::system>,
- unit<temperature_dimension,SI::system> > :
+struct is_implicitly_convertible<unit<temperature_dimension,fahrenheit::system>,
+ unit<temperature_dimension,SI::system> > :
public mpl::true_
{ };
template<>
-struct is_implicitly_convertible<absolute< unit<temperature_dimension,fahrenheit::system> >,
- absolute< unit<temperature_dimension,SI::system> > > :
+struct is_implicitly_convertible<
+ absolute< unit<temperature_dimension,fahrenheit::system> >,
+ absolute< unit<temperature_dimension,SI::system> > > :
public mpl::true_
{ };
//]
@@ -88,8 +89,10 @@
std::stringstream sstream1, sstream2;
//[temperature_snippet_3
- quantity<absolute<fahrenheit::temperature> > T1p(32.0*absolute<fahrenheit::temperature>());
- quantity<fahrenheit::temperature> T1v(32.0*fahrenheit::degrees);
+ quantity<absolute<fahrenheit::temperature> > T1p(
+ 32.0*absolute<fahrenheit::temperature>());
+ quantity<fahrenheit::temperature> T1v(
+ 32.0*fahrenheit::degrees);
quantity<absolute<SI::temperature> > T2p(T1p);
quantity<absolute<SI::temperature> > T3p = T1p;
@@ -97,10 +100,12 @@
quantity<SI::temperature> T3v = T1v;
//]
- typedef conversion_helper<quantity<absolute<fahrenheit::temperature> >,
- quantity<absolute<SI::temperature> > > absolute_conv_type;
- typedef conversion_helper<quantity<fahrenheit::temperature>,
- quantity<SI::temperature> > relative_conv_type;
+ typedef conversion_helper<
+ quantity<absolute<fahrenheit::temperature> >,
+ quantity<absolute<SI::temperature> > > absolute_conv_type;
+ typedef conversion_helper<
+ quantity<fahrenheit::temperature>,
+ quantity<SI::temperature> > relative_conv_type;
sstream1 << T1p << std::endl
<< absolute_conv_type::convert(T1p) << std::endl
@@ -137,14 +142,16 @@
if(str1.size() < str2.size())
{
- std::string::iterator iter = std::mismatch(str1.begin(), str1.end(), str2.begin()).first;
+ std::string::iterator iter =
+ std::mismatch(str1.begin(), str1.end(), str2.begin()).first;
std::cout << iter - str1.begin() << std::endl;
std::cout << std::count(str1.begin(), iter, '\n') << std::endl;
}
else
{
- std::string::iterator iter = std::mismatch(str2.begin(), str2.end(), str1.begin()).first;
+ std::string::iterator iter =
+ std::mismatch(str2.begin(), str2.end(), str1.begin()).first;
std::cout << iter - str2.begin() << std::endl;
std::cout << std::count(str2.begin(), iter, '\n') << std::endl;
Modified: sandbox/units/libs/units/example/test_system.hpp
==============================================================================
--- sandbox/units/libs/units/example/test_system.hpp (original)
+++ sandbox/units/libs/units/example/test_system.hpp 2008-01-19 17:35:35 EST (Sat, 19 Jan 2008)
@@ -28,16 +28,31 @@
namespace units {
//[test_system_snippet_1
-struct length_base_dimension : boost::units::base_dimension<length_base_dimension,1> { }; ///> base dimension of length
-struct mass_base_dimension : boost::units::base_dimension<mass_base_dimension,2> { }; ///> base dimension of mass
-struct time_base_dimension : boost::units::base_dimension<time_base_dimension,3> { }; ///> base dimension of time
+
+/// base dimension of length
+struct length_base_dimension : base_dimension<length_base_dimension,1> { };
+/// base dimension of mass
+struct mass_base_dimension : base_dimension<mass_base_dimension,2> { };
+/// base dimension of time
+struct time_base_dimension : base_dimension<time_base_dimension,3> { };
+
//]
#if 0
//[test_system_snippet_2
-typedef make_dimension_list< boost::mpl::list< dim< length_base_dimension,static_rational<1> > > >::type length_dimension;
-typedef make_dimension_list< boost::mpl::list< dim< mass_base_dimension,static_rational<1> > > >::type mass_dimension;
-typedef make_dimension_list< boost::mpl::list< dim< time_base_dimension,static_rational<1> > > >::type time_dimension;
+
+typedef make_dimension_list<
+ boost::mpl::list< dim< length_base_dimension,static_rational<1> > >
+>::type length_dimension;
+
+typedef make_dimension_list<
+ boost::mpl::list< dim< mass_base_dimension,static_rational<1> > >
+>::type mass_dimension;
+
+typedef make_dimension_list<
+ boost::mpl::list< dim< time_base_dimension,static_rational<1> > >
+>::type time_dimension;
+
//]
#endif
@@ -49,10 +64,17 @@
#if 0
//[test_system_snippet_4
-typedef make_dimension_list< boost::mpl::list< dim< length_base_dimension,static_rational<2> > > >::type area_dimension;
-typedef make_dimension_list< boost::mpl::list< dim< mass_base_dimension,static_rational<1> >,
- dim< length_base_dimension,static_rational<2> >,
- dim< time_base_dimension,static_rational<-2> > > >::type energy_dimension;
+
+typedef make_dimension_list<
+ boost::mpl::list< dim< length_base_dimension,static_rational<2> > >
+>::type area_dimension;
+
+typedef make_dimension_list<
+ boost::mpl::list< dim< mass_base_dimension,static_rational<1> >,
+ dim< length_base_dimension,static_rational<2> >,
+ dim< time_base_dimension,static_rational<-2> > >
+>::type energy_dimension;
+
//]
#endif
@@ -67,15 +89,18 @@
//[test_system_snippet_6
-struct meter_base_unit : base_unit<meter_base_unit, length_dimension, 1> { };
-struct kilogram_base_unit : base_unit<kilogram_base_unit, mass_dimension, 2> { };
-struct second_base_unit : base_unit<second_base_unit, time_dimension, 3> { };
+struct meter_base_unit : base_unit<meter_base_unit, length_dimension, 1> {};
+struct kilogram_base_unit : base_unit<kilogram_base_unit, mass_dimension, 2> {};
+struct second_base_unit : base_unit<second_base_unit, time_dimension, 3> {};
typedef make_system<meter_base_unit>::type m_system;
typedef make_system<kilogram_base_unit>::type kg_system;
typedef make_system<second_base_unit>::type s_system;
-typedef make_system<meter_base_unit,kilogram_base_unit,second_base_unit>::type mks_system;
+typedef make_system<
+ meter_base_unit,
+ kilogram_base_unit,
+ second_base_unit>::type mks_system;
/// unit typedefs
typedef unit<dimensionless_type,mks_system> dimensionless;
Modified: sandbox/units/libs/units/example/tutorial.cpp
==============================================================================
--- sandbox/units/libs/units/example/tutorial.cpp (original)
+++ sandbox/units/libs/units/example/tutorial.cpp 2008-01-19 17:35:35 EST (Sat, 19 Jan 2008)
@@ -72,9 +72,9 @@
/// check complex quantities
typedef std::complex<double> complex_type;
- quantity<electric_potential,complex_type> v = complex_type(12.5,0.0)*volts;
- quantity<current,complex_type> i = complex_type(3.0,4.0)*amperes;
- quantity<resistance,complex_type> z = complex_type(1.5,-2.0)*ohms;
+ quantity<electric_potential,complex_type> v = complex_type(12.5,0.0)*volts;
+ quantity<current,complex_type> i = complex_type(3.0,4.0)*amperes;
+ quantity<resistance,complex_type> z = complex_type(1.5,-2.0)*ohms;
std::cout << "V = " << v << std::endl
<< "I = " << i << std::endl
Modified: sandbox/units/libs/units/example/unit.cpp
==============================================================================
--- sandbox/units/libs/units/example/unit.cpp (original)
+++ sandbox/units/libs/units/example/unit.cpp 2008-01-19 17:35:35 EST (Sat, 19 Jan 2008)
@@ -65,9 +65,11 @@
<< "M*(L/T)*(L/T) = " << M*(L/T)*(L/T) << std::endl
<< "M*(L/T)^2 = " << M*pow<2>(L/T) << std::endl
<< "L^3 = " << pow<3>(L) << std::endl
- << "L^(3/2) = " << pow<static_rational<3,2> >(L) << std::endl
+ << "L^(3/2) = " << pow<static_rational<3,2> >(L)
+ << std::endl
<< "2vM = " << root<2>(M) << std::endl
- << "(3/2)vM = " << root<static_rational<3,2> >(M) << std::endl;
+ << "(3/2)vM = " << root<static_rational<3,2> >(M)
+ << std::endl;
sstream2 << "L = m" << std::endl
<< "L+L = m" << std::endl
@@ -96,14 +98,16 @@
if(str1.size() < str2.size())
{
- std::string::iterator iter = std::mismatch(str1.begin(), str1.end(), str2.begin()).first;
+ std::string::iterator iter =
+ std::mismatch(str1.begin(), str1.end(), str2.begin()).first;
std::cout << iter - str1.begin() << std::endl;
std::cout << std::count(str1.begin(), iter, '\n') << std::endl;
}
else
{
- std::string::iterator iter = std::mismatch(str2.begin(), str2.end(), str1.begin()).first;
+ std::string::iterator iter =
+ std::mismatch(str2.begin(), str2.end(), str1.begin()).first;
std::cout << iter - str2.begin() << std::endl;
std::cout << std::count(str2.begin(), iter, '\n') << std::endl;
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