summaryrefslogtreecommitdiff
path: root/boost/units
diff options
context:
space:
mode:
Diffstat (limited to 'boost/units')
-rw-r--r--boost/units/conversion.hpp6
-rw-r--r--boost/units/detail/one.hpp11
-rw-r--r--boost/units/detail/static_rational_power.hpp4
-rw-r--r--boost/units/quantity.hpp36
-rw-r--r--boost/units/systems/detail/constants.hpp68
5 files changed, 121 insertions, 4 deletions
diff --git a/boost/units/conversion.hpp b/boost/units/conversion.hpp
index 5f739aa188..beb641516e 100644
--- a/boost/units/conversion.hpp
+++ b/boost/units/conversion.hpp
@@ -170,10 +170,12 @@ BOOST_UNITS_DEFAULT_CONVERSION(namespace_::name_ ## _base_unit, unit)
/// Find the conversion factor between two units.
template<class FromUnit,class ToUnit>
inline
-typename detail::conversion_factor_helper<FromUnit, ToUnit>::type
+typename one_to_double_type<
+ typename detail::conversion_factor_helper<FromUnit, ToUnit>::type
+>::type
conversion_factor(const FromUnit&,const ToUnit&)
{
- return(detail::conversion_factor_helper<FromUnit, ToUnit>::value());
+ return(one_to_double(detail::conversion_factor_helper<FromUnit, ToUnit>::value()));
}
} // namespace units
diff --git a/boost/units/detail/one.hpp b/boost/units/detail/one.hpp
index 4cadc2c5fc..bf1cad902b 100644
--- a/boost/units/detail/one.hpp
+++ b/boost/units/detail/one.hpp
@@ -102,6 +102,17 @@ inline bool operator>(const boost::units::one&, const T& t) {
return(1 > t);
}
+template<class T>
+T one_to_double(const T& t) { return t; }
+
+inline double one_to_double(const one&) { return 1.0; }
+
+template<class T>
+struct one_to_double_type { typedef T type; };
+
+template<>
+struct one_to_double_type<one> { typedef double type; };
+
} // namespace units
} // namespace boost
diff --git a/boost/units/detail/static_rational_power.hpp b/boost/units/detail/static_rational_power.hpp
index 9c71f55ab7..66c9d9d04b 100644
--- a/boost/units/detail/static_rational_power.hpp
+++ b/boost/units/detail/static_rational_power.hpp
@@ -93,7 +93,7 @@ struct static_int_power_impl<N, true>
typedef typename next::type type;
static type call(const Y& y, const R& r)
{
- const Y square = y * y;
+ const square_type square = y * y;
return(next::call(square, r));
}
};
@@ -185,7 +185,7 @@ struct static_rational_power_impl<static_rational<N, 1>, Y>
{
typedef typename static_int_power_sign_impl<N>::template apply<Y> impl;
typedef typename impl::type type;
- static Y call(const Y& y)
+ static type call(const Y& y)
{
return(impl::call(y));
}
diff --git a/boost/units/quantity.hpp b/boost/units/quantity.hpp
index 4fe916dcc4..3cd6682ce4 100644
--- a/boost/units/quantity.hpp
+++ b/boost/units/quantity.hpp
@@ -680,6 +680,15 @@ struct multiply_typeof_helper< X,quantity<Unit,Y> >
typedef quantity<unit_type,value_type> type;
};
+/// disambiguate
+/// INTERNAL ONLY
+template<class Unit,
+ class Y>
+struct multiply_typeof_helper< one,quantity<Unit,Y> >
+{
+ typedef quantity<Unit,Y> type;
+};
+
/// quantity times scalar typeof helper
/// INTERNAL ONLY
template<class Unit,
@@ -692,6 +701,15 @@ struct multiply_typeof_helper< quantity<Unit,X>,Y >
typedef quantity<unit_type,value_type> type;
};
+/// disambiguate
+/// INTERNAL ONLY
+template<class Unit,
+ class X>
+struct multiply_typeof_helper< quantity<Unit,X>,one >
+{
+ typedef quantity<Unit,X> type;
+};
+
/// unit times quantity typeof helper
/// INTERNAL ONLY
template<class Unit,
@@ -767,6 +785,15 @@ struct divide_typeof_helper< X,quantity<Unit,Y> >
typedef quantity<unit_type,value_type> type;
};
+/// disambiguate
+/// INTERNAL ONLY
+template<class Unit,
+ class Y>
+struct divide_typeof_helper< one,quantity<Unit,Y> >
+{
+ typedef quantity<Unit,Y> type;
+};
+
/// quantity divided by scalar typeof helper
/// INTERNAL ONLY
template<class Unit,
@@ -779,6 +806,15 @@ struct divide_typeof_helper< quantity<Unit,X>,Y >
typedef quantity<unit_type,value_type> type;
};
+/// disambiguate
+/// INTERNAL ONLY
+template<class Unit,
+ class X>
+struct divide_typeof_helper< quantity<Unit,X>,one >
+{
+ typedef quantity<Unit,X> type;
+};
+
/// unit divided by quantity typeof helper
/// INTERNAL ONLY
template<class Unit,
diff --git a/boost/units/systems/detail/constants.hpp b/boost/units/systems/detail/constants.hpp
index fac9b612cc..cf156f7072 100644
--- a/boost/units/systems/detail/constants.hpp
+++ b/boost/units/systems/detail/constants.hpp
@@ -20,6 +20,8 @@
#include <boost/units/static_constant.hpp>
#include <boost/units/units_fwd.hpp>
#include <boost/units/operators.hpp>
+#include <boost/units/static_rational.hpp>
+#include <boost/units/detail/one.hpp>
namespace boost {
@@ -134,6 +136,72 @@ BOOST_UNITS_DEFINE_HELPER(divide, /)
#undef BOOST_UNITS_DEFINE_HELPER
+#define BOOST_UNITS_DEFINE_HELPER(name, symbol) \
+ \
+template<class T1> \
+struct name ## _typeof_helper<constant<T1>, one> \
+{ \
+ typedef typename name ## _typeof_helper<typename T1::value_type, one>::type type;\
+}; \
+ \
+template<class T2> \
+struct name ## _typeof_helper<one, constant<T2> > \
+{ \
+ typedef typename name ## _typeof_helper<one, typename T2::value_type>::type type;\
+}; \
+ \
+template<class T1> \
+typename name ## _typeof_helper<typename T1::value_type, one>::type \
+operator symbol(const constant<T1>& t, const one& u) \
+{ \
+ return(t.value() symbol u); \
+} \
+ \
+template<class T2> \
+typename name ## _typeof_helper<one, typename T2::value_type>::type \
+operator symbol(const one& t, const constant<T2>& u) \
+{ \
+ return(t symbol u.value()); \
+}
+
+BOOST_UNITS_DEFINE_HELPER(multiply, *)
+BOOST_UNITS_DEFINE_HELPER(divide, /)
+
+#undef BOOST_UNITS_DEFINE_HELPER
+
+template<class T1, long N, long D>
+struct power_typeof_helper<constant<T1>, static_rational<N,D> >
+{
+ typedef power_typeof_helper<typename T1::value_type, static_rational<N,D> > base;
+ typedef typename base::type type;
+ static type value(const constant<T1>& arg)
+ {
+ return base::value(arg.value());
+ }
+};
+
+#define BOOST_UNITS_DEFINE_HELPER(name, symbol) \
+ \
+template<class T1, class E> \
+struct name ## _typeof_helper<constant<T1> > \
+{ \
+ typedef typename name ## _typeof_helper<typename T1::value_type, E>::type type;\
+}; \
+ \
+template<class T1> \
+typename name ## _typeof_helper<typename T1::value_type, one>::type \
+operator symbol(const constant<T1>& t, const one& u) \
+{ \
+ return(t.value() symbol u); \
+} \
+ \
+template<class T2> \
+typename name ## _typeof_helper<one, typename T2::value_type>::type \
+operator symbol(const one& t, const constant<T2>& u) \
+{ \
+ return(t symbol u.value()); \
+}
+
#define BOOST_UNITS_PHYSICAL_CONSTANT(name, type, value_, uncertainty_) \
struct name ## _t { \
typedef type value_type; \