00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014 #ifndef PHYSICAL_DYNAMICPHYSICAL_IMPL
00015 #define PHYSICAL_DYNAMICPHYSICAL_IMPL
00016
00017 #include "physical/dynamicphysical.hpp"
00018 #include "physical/dynamicunit.hpp"
00019
00020 namespace physical {
00021
00022 template<class UnitSystem>
00023 DynamicPhysical<UnitSystem>& DynamicPhysical<UnitSystem>::operator*=(DynamicPhysical<UnitSystem> b){
00024 *this = *this * b;
00025 return *this;
00026 };
00027
00028
00029
00030
00031 template<class UnitSystem>
00032 DynamicPhysical<UnitSystem>
00033 operator+(DynamicPhysical<UnitSystem> a, DynamicPhysical<UnitSystem> b) {
00034 if (a.exponents != b.exponents)
00035 throw IncompatibleUnitException("cannot add quantities with different dimensions");
00036 return DynamicPhysical<UnitSystem>(a.numerical_value+b.numerical_value, a.exponents);
00037 };
00038
00039 template<class UnitSystem>
00040 DynamicPhysical<UnitSystem>
00041 operator-(DynamicPhysical<UnitSystem> a, DynamicPhysical<UnitSystem> b) {
00042 if (a.exponents != b.exponents)
00043 throw IncompatibleUnitException("cannot substract quantities with different dimensions");
00044 return DynamicPhysical<UnitSystem>(a.numerical_value-b.numerical_value, a.exponents);
00045 };
00046
00047
00048 template<class UnitSystem>
00049 DynamicPhysical<UnitSystem>
00050 operator*(DynamicPhysical<UnitSystem> a, DynamicPhysical<UnitSystem> b) {
00051 return DynamicPhysical<UnitSystem>(a.numerical_value*b.numerical_value, a.exponents+b.exponents);
00052 };
00053
00054 template<class UnitSystem>
00055 DynamicPhysical<UnitSystem>
00056 operator*(double a, DynamicPhysical<UnitSystem> b) {
00057 return DynamicPhysical<UnitSystem>(a*b.numerical_value, b.exponents);
00058 };
00059
00060
00061 template<class UnitSystem>
00062 DynamicPhysical<UnitSystem>
00063 operator/(DynamicPhysical<UnitSystem> a, DynamicPhysical<UnitSystem> b) {
00064 return DynamicPhysical<UnitSystem>(a.numerical_value / b.numerical_value, a.exponents-b.exponents);
00065 };
00066
00067
00068
00069 template<class UnitSystem>
00070 bool operator==(DynamicPhysical<UnitSystem> a, DynamicPhysical<UnitSystem> b) {
00071 if (a.exponents != b.exponents){
00072 throw IncompatibleUnitException("cannot compare quantities with different dimensions");
00073 };
00074 return a==b;
00075 };
00076
00077 template<class UnitSystem>
00078 bool operator!=(DynamicPhysical<UnitSystem> a, DynamicPhysical<UnitSystem> b) {
00079 if (a.exponents != b.exponents){
00080 throw IncompatibleUnitException("cannot compare quantities with different dimensions");
00081 };
00082 return a!=b;
00083 };
00084
00085 template<class UnitSystem>
00086 bool operator>=(DynamicPhysical<UnitSystem> a, DynamicPhysical<UnitSystem> b) {
00087 if (a.exponents != b.exponents){
00088 throw IncompatibleUnitException("cannot compare quantities with different dimensions");
00089 };
00090 return a>=b;
00091 };
00092
00093 template<class UnitSystem>
00094 bool operator<=(DynamicPhysical<UnitSystem> a, DynamicPhysical<UnitSystem> b) {
00095 if (a.exponents != b.exponents){
00096 throw IncompatibleUnitException("cannot compare quantities with different dimensions");
00097 };
00098 return a<=b;
00099 };
00100
00101 template<class UnitSystem>
00102 bool operator>(DynamicPhysical<UnitSystem> a, DynamicPhysical<UnitSystem> b) {
00103 if (a.exponents != b.exponents){
00104 throw IncompatibleUnitException("cannot compare quantities with different dimensions");
00105 };
00106 return a>b;
00107 };
00108
00109 template<class UnitSystem>
00110 bool operator<(DynamicPhysical<UnitSystem> a, DynamicPhysical<UnitSystem> b) {
00111 if (a.exponents != b.exponents){
00112 throw IncompatibleUnitException("cannot compare quantities with different dimensions");
00113 };
00114 return a<b;
00115 };
00116
00117
00118
00119 template<class UnitSystem>
00120 DynamicPhysical<UnitSystem> power(DynamicPhysical<UnitSystem> a, int n) {
00121 DynamicPhysical r=1.;
00122 while(n>0) {r=r*a; --n;};
00123 while(n<0) {r=r/a; ++n;};
00124 return r;
00125 };
00126
00127
00128
00129
00130 template<class UnitSystem>
00131 DynamicPhysical<UnitSystem> operator*(double real, const DynamicUnit<UnitSystem>& unit)
00132 {
00133 return DynamicPhysical<UnitSystem>(real*unit.scale.factor + unit.scale.origin, unit.exponents);
00134 };
00135
00136
00137 template<class UnitSystem>
00138 DynamicPhysical<UnitSystem> operator/(DynamicPhysical<UnitSystem> quantity, const DynamicUnit<UnitSystem> unit)
00139 {
00140 return DynamicPhysical<UnitSystem>((quantity.numerical_value - unit.scale.origin)/ unit.scale.factor, unit.exponents);
00141 };
00142
00143 };
00144
00145
00146 #endif // PHYSICAL_DYNAMICPHYSICAL_IMPL