Boost logo

Boost-Commit :

From: boost_at_[hidden]
Date: 2007-12-06 17:59:36


Author: matthiasschabel
Date: 2007-12-06 17:59:36 EST (Thu, 06 Dec 2007)
New Revision: 41811
URL: http://svn.boost.org/trac/boost/changeset/41811

Log:
comment out scalar/quantity multiplication and division operators for mixed types
Text files modified:
   sandbox/units/boost/units/quantity.hpp | 88 ++++++++++++++++++++++++++++++---------
   sandbox/units/libs/units/example/performance.cpp | 14 +++---
   2 files changed, 75 insertions(+), 27 deletions(-)

Modified: sandbox/units/boost/units/quantity.hpp
==============================================================================
--- sandbox/units/boost/units/quantity.hpp (original)
+++ sandbox/units/boost/units/quantity.hpp 2007-12-06 17:59:36 EST (Thu, 06 Dec 2007)
@@ -810,54 +810,102 @@
     return type::from_value(lhs);
 }
 
+///// runtime quantity times scalar
+//template<class Unit,
+// class X,
+// class Y>
+//inline
+//typename multiply_typeof_helper< quantity<Unit,X>,Y >::type
+//operator*(const quantity<Unit,X>& lhs,const Y& rhs)
+//{
+// typedef typename multiply_typeof_helper< quantity<Unit,X>,Y >::type type;
+//
+// return type::from_value(lhs.value()*rhs);
+//}
+//
+///// runtime scalar times quantity
+//template<class Unit,
+// class X,
+// class Y>
+//inline
+//typename multiply_typeof_helper< X,quantity<Unit,Y> >::type
+//operator*(const X& lhs,const quantity<Unit,Y>& rhs)
+//{
+// typedef typename multiply_typeof_helper< X,quantity<Unit,Y> >::type type;
+//
+// return type::from_value(lhs*rhs.value());
+//}
+
 /// runtime quantity times scalar
 template<class Unit,
- class X,
- class Y>
+ class X>
 inline
-typename multiply_typeof_helper< quantity<Unit,X>,Y >::type
-operator*(const quantity<Unit,X>& lhs,const Y& rhs)
+typename multiply_typeof_helper< quantity<Unit,X>,X >::type
+operator*(const quantity<Unit,X>& lhs,const X& rhs)
 {
- typedef typename multiply_typeof_helper< quantity<Unit,X>,Y >::type type;
+ typedef typename multiply_typeof_helper< quantity<Unit,X>,X >::type type;
     
     return type::from_value(lhs.value()*rhs);
 }
 
 /// runtime scalar times quantity
 template<class Unit,
- class X,
- class Y>
+ class X>
 inline
-typename multiply_typeof_helper< X,quantity<Unit,Y> >::type
-operator*(const X& lhs,const quantity<Unit,Y>& rhs)
+typename multiply_typeof_helper< X,quantity<Unit,X> >::type
+operator*(const X& lhs,const quantity<Unit,X>& rhs)
 {
- typedef typename multiply_typeof_helper< X,quantity<Unit,Y> >::type type;
+ typedef typename multiply_typeof_helper< X,quantity<Unit,X> >::type type;
     
     return type::from_value(lhs*rhs.value());
 }
 
+///// runtime quantity divided by scalar
+//template<class Unit,
+// class X,
+// class Y>
+//inline
+//typename divide_typeof_helper< quantity<Unit,X>,Y >::type
+//operator/(const quantity<Unit,X>& lhs,const Y& rhs)
+//{
+// typedef typename divide_typeof_helper< quantity<Unit,X>,Y >::type type;
+//
+// return type::from_value(lhs.value()/rhs);
+//}
+//
+///// runtime scalar divided by quantity
+//template<class Unit,
+// class X,
+// class Y>
+//inline
+//typename divide_typeof_helper< X,quantity<Unit,Y> >::type
+//operator/(const X& lhs,const quantity<Unit,Y>& rhs)
+//{
+// typedef typename divide_typeof_helper< X,quantity<Unit,Y> >::type type;
+//
+// return type::from_value(lhs/rhs.value());
+//}
+
 /// runtime quantity divided by scalar
 template<class Unit,
- class X,
- class Y>
+ class X>
 inline
-typename divide_typeof_helper< quantity<Unit,X>,Y >::type
-operator/(const quantity<Unit,X>& lhs,const Y& rhs)
+typename divide_typeof_helper< quantity<Unit,X>,X >::type
+operator/(const quantity<Unit,X>& lhs,const X& rhs)
 {
- typedef typename divide_typeof_helper< quantity<Unit,X>,Y >::type type;
+ typedef typename divide_typeof_helper< quantity<Unit,X>,X >::type type;
     
     return type::from_value(lhs.value()/rhs);
 }
 
 /// runtime scalar divided by quantity
 template<class Unit,
- class X,
- class Y>
+ class X>
 inline
-typename divide_typeof_helper< X,quantity<Unit,Y> >::type
-operator/(const X& lhs,const quantity<Unit,Y>& rhs)
+typename divide_typeof_helper< X,quantity<Unit,X> >::type
+operator/(const X& lhs,const quantity<Unit,X>& rhs)
 {
- typedef typename divide_typeof_helper< X,quantity<Unit,Y> >::type type;
+ typedef typename divide_typeof_helper< X,quantity<Unit,X> >::type type;
     
     return type::from_value(lhs/rhs.value());
 }

Modified: sandbox/units/libs/units/example/performance.cpp
==============================================================================
--- sandbox/units/libs/units/example/performance.cpp (original)
+++ sandbox/units/libs/units/example/performance.cpp 2007-12-06 17:59:36 EST (Thu, 06 Dec 2007)
@@ -96,15 +96,15 @@
 
 template<class F, class T, class N, class R>
 R solve_differential_equation(F f, T lower, T upper, N steps, R start) {
- T h = (upper - lower) / steps;
+ T h = (upper - lower) / (1.0*steps);
     for(N i = N(); i < steps; ++i) {
         R y = start;
- T x = lower + h * i;
+ 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, y + h * k1 / 2);
- typename F::template result<T, R>::type k3 = f(x + h/2, y + h * k2 / 2);
+ 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);
- start = y + h * (k1 + 2 * k2 + 2 * k3 + k4) / 6;
+ start = y + h * (k1 + 2.0 * k2 + 2.0 * k3 + k4) / 6.0;
     }
     return(start);
 }
@@ -116,14 +116,14 @@
     template<class Arg1, class Arg2> struct result;
     
     double operator()(const double& x, const double& y) const {
- return(1 - x + 4 * y);
+ return(1.0 - x + 4.0 * y);
     }
 
     boost::units::quantity<boost::units::SI::velocity>
     operator()(const quantity<SI::time>& x, const quantity<SI::length>& y) const {
         using namespace boost::units;
         using namespace SI;
- return(1 * meters / second - x * meters / pow<2>(seconds) + 4 * y / seconds );
+ return(1.0 * meters / second - x * meters / pow<2>(seconds) + 4.0 * y / seconds );
     }
 };
 


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