00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014 #ifndef PHYSICAL_FIXEDPHYSICAL
00015 #define PHYSICAL_FIXEDPHYSICAL
00016
00017 #include "physical/detail/fixedexponents.hpp"
00018 #include "physical/detail/larger_type.hpp"
00019
00020
00026 namespace physical {
00027
00028 struct DynamicPhysical;
00029
00031 template<typename T, class Exponents>
00032 struct FixedPhysical{
00033 typedef Exponents exponents;
00034 typedef T numerical_value_t;
00035 numerical_value_t numerical_value;
00036
00038 explicit FixedPhysical(numerical_value_t v):numerical_value(v){};
00039
00041 FixedPhysical(const FixedPhysical& v): numerical_value(v.numerical_value){};
00042
00044 FixedPhysical(const DynamicPhysical& v);
00045
00047 template<typename T2>
00048 FixedPhysical(const FixedPhysical<T2, exponents>& v): numerical_value(v.numerical_value){};
00049
00050
00051 };
00052
00053
00055 template <class Q1, class Q2>
00056 struct FixedPhysicalSum{
00057 typedef typename Q1::exponents E1;
00058 typedef typename Q2::exponents E2;
00059 BOOST_STATIC_ASSERT((boost::is_same<typename E1::dimensions, typename E2::dimensions>::type::value ));
00060 typedef typename detail::larger_type<typename Q1::numerical_value_t, typename Q2::numerical_value_t>::type numerical_value_t;
00061 typedef FixedPhysical< numerical_value_t, typename Q1::exponents > type;
00062 };
00063
00064
00065
00067 template <class E1, class E2>
00068 struct FixedPhysicalRatio{
00069 typedef typename detail::larger_type<typename E1::numerical_value_t, typename E2::numerical_value_t>::type numerical_value_t;
00070 typedef FixedPhysical< numerical_value_t, typename detail::minus<typename E1::exponents, typename E2::exponents>::type > type;
00071 };
00072
00074 template <class Q1, class Q2>
00075 struct FixedPhysicalProduct{
00076 typedef typename detail::larger_type<typename Q1::numerical_value_t, typename Q2::numerical_value_t>::type numerical_value_t;
00077 typedef FixedPhysical< numerical_value_t, typename detail::plus<typename Q1::exponents, typename Q2::exponents>::type > type;
00078 };
00079
00080
00081
00082 template<typename T1, typename T2, class exponents>
00083 typename FixedPhysicalSum< FixedPhysical<T1, exponents>, FixedPhysical<T2, exponents> >::type
00084 operator+(const FixedPhysical<T1, exponents> a, FixedPhysical<T2, exponents> b){
00085 typedef FixedPhysicalSum<FixedPhysical<T1, exponents>, FixedPhysical<T2, exponents> >::type return_type;
00086 return retrun_type(a.numerical_value + b.numerical_value);
00087 };
00088
00089 template<typename T1, typename T2, class exponents>
00090 typename FixedPhysicalSum< FixedPhysical<T1, exponents>, FixedPhysical<T2, exponents> >::type
00091 operator-(const FixedPhysical<T1, exponents> a, FixedPhysical<T2, exponents> b){
00092 typedef FixedPhysicalSum<FixedPhysical<T1, exponents>, FixedPhysical<T2, exponents> >::type return_type;
00093 return retrun_type(a.numerical_value - b.numerical_value);
00094 };
00095
00096 template<typename T1, typename T2, class exponents1, class exponents2>
00097 typename FixedPhysicalProduct< FixedPhysical<T1, exponents1>, FixedPhysical<T2, exponents2> >::type
00098 operator*(const FixedPhysical<T1, exponents1> a, FixedPhysical<T2, exponents2> b){
00099 typedef FixedPhysicalProduct<FixedPhysical<T1, exponents1>, FixedPhysical<T2, exponents2> >::type return_type;
00100 return return_type(a.numerical_value * b.numerical_value);
00101 };
00102
00103 template<typename T1, typename T2, class exponents1, class exponents2>
00104 typename FixedPhysicalRatio< FixedPhysical<T1, exponents1>, FixedPhysical<T2, exponents2> >::type
00105 operator/(const FixedPhysical<T1, exponents1> a, FixedPhysical<T2, exponents2> b){
00106 typedef FixedPhysicalRatio<FixedPhysical<T1, exponents1>, FixedPhysical<T2, exponents2> >::type return_type;
00107 return return_type(a.numerical_value / b.numerical_value);
00108 };
00109
00110
00111
00112 template<typename T1, typename T2, class exponents>
00113 bool
00114 operator==(const FixedPhysical<T1, exponents> a, FixedPhysical<T2, exponents> b){
00115 return retrun_type(a.numerical_value == b.numerical_value);
00116 };
00117
00118 template<typename T1, typename T2, class exponents>
00119 bool
00120 operator!=(const FixedPhysical<T1, exponents> a, FixedPhysical<T2, exponents> b){
00121 return retrun_type(a.numerical_value != b.numerical_value);
00122 };
00123
00124 template<typename T1, typename T2, class exponents>
00125 bool
00126 operator>=(const FixedPhysical<T1, exponents> a, FixedPhysical<T2, exponents> b){
00127 return retrun_type(a.numerical_value >= b.numerical_value);
00128 };
00129
00130 template<typename T1, typename T2, class exponents>
00131 bool
00132 operator<=(const FixedPhysical<T1, exponents> a, FixedPhysical<T2, exponents> b){
00133 return retrun_type(a.numerical_value <= b.numerical_value);
00134 };
00135
00136 template<typename T1, typename T2, class exponents>
00137 bool
00138 operator>(const FixedPhysical<T1, exponents> a, FixedPhysical<T2, exponents> b){
00139 return retrun_type(a.numerical_value > b.numerical_value);
00140 };
00141
00142 template<typename T1, typename T2, class exponents>
00143 bool
00144 operator<(const FixedPhysical<T1, exponents> a, FixedPhysical<T2, exponents> b){
00145 return retrun_type(a.numerical_value < b.numerical_value);
00146 };
00147
00148
00149 template <typename T, int P>
00150 struct FixedPhysicalBase{
00151 typedef FixedPhysical< T, typename detail::FixExponents<P>::type > type;
00152 };
00153
00154
00155 template <typename T>
00156 struct FixedPhysicalBase<T, -1>{
00157 typedef FixedPhysical< T,
00158 detail::FixedExponents<typename detail::zero_vector<config::number_baseunits>::type>
00159 > type;
00160 };
00161
00162
00163
00164 template<typename T1, typename T2, class exponents1>
00165 FixedPhysical<typename detail::larger_type<T1, T2>::type, exponents1>
00166 operator*(const T1 a, const FixedPhysical<T2, exponents1> b){
00167 typedef FixedPhysical<typename detail::larger_type<T1, T2>::type, exponents1> return_type;
00168 return return_type(a * b.numerical_value);
00169 };
00170
00171 };
00172
00173 #endif