00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032 #ifndef MORE_NUM_OPTYPE_H
00033 #define MORE_NUM_OPTYPE_H
00034
00035
00036
00037 namespace more {
00038 namespace num {
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057 template <class T> struct additive_identity {};
00058
00059 template<> struct additive_identity<double>
00060 { operator double() { return 0.0; } };
00061 template<> struct additive_identity<int>
00062 { operator int() { return 0; } };
00063 template<> struct additive_identity<long int>
00064 { operator long int() { return 0L; } };
00065
00066 template <class T>
00067 struct multiplicative_identity {};
00068
00069 template<> struct multiplicative_identity<double>
00070 { operator double() { return 1.0; } };
00071 template<> struct multiplicative_identity<int>
00072 { operator int() { return 1; } };
00073 template<> struct multiplicative_identity<long int>
00074 { operator long int() { return 1L; }};
00075
00076
00077
00078
00079
00080
00081 template <class T, class U>
00082 struct balanced_type {};
00083 template <class T, class U>
00084 struct plus_type { typedef typename balanced_type<T, U>::self self; };
00085 template <class T, class U>
00086 struct minus_type { typedef typename plus_type<T, U>::self self; };
00087 template <class T, class U>
00088 struct times_type { typedef typename balanced_type<T, U>::self self; };
00089 template <class T, class U>
00090 struct divides_type { typedef typename times_type<T, U>::self self; };
00091 template <class T, class U>
00092 struct remainder_type { typedef typename divides_type<T, U>::self self; };
00093 template <class T>
00094 struct negation_type { typedef T self; };
00095 template <class T>
00096 struct inverse_type { typedef void self; };
00097
00098
00099
00100
00101
00102
00103
00104
00105
00106
00107
00108 template<> struct balanced_type<char, char> { typedef char self; };
00109
00110 template<> struct balanced_type<short, short> { typedef short self; };
00111 template<> struct balanced_type<char, short> { typedef short self; };
00112 template<> struct balanced_type<short, char> { typedef short self; };
00113
00114 template<> struct balanced_type<int, int> { typedef int self; };
00115 template<> struct balanced_type<short, int> { typedef int self; };
00116 template<> struct balanced_type<int, short> { typedef int self; };
00117 template<> struct balanced_type<char, int> { typedef int self; };
00118 template<> struct balanced_type<int, char> { typedef int self; };
00119
00120 template<> struct balanced_type<long, long> { typedef long self; };
00121 template<> struct balanced_type<long, int> { typedef long self; };
00122 template<> struct balanced_type<int, long> { typedef long self; };
00123 template<> struct balanced_type<long, short> { typedef long self; };
00124 template<> struct balanced_type<short, long> { typedef long self; };
00125 template<> struct balanced_type<long, char> { typedef long self; };
00126 template<> struct balanced_type<char, long> { typedef long self; };
00127
00128
00129
00130
00131 template<> struct balanced_type<float, float> { typedef float self; };
00132
00133 template<> struct balanced_type<double, double> { typedef double self; };
00134 template<> struct balanced_type<double, float> { typedef double self; };
00135 template<> struct balanced_type<float, double> { typedef double self; };
00136
00137 template<> struct balanced_type<long double, long double>
00138 { typedef long double self; };
00139 template<> struct balanced_type<long double, float>
00140 { typedef long double self; };
00141 template<> struct balanced_type<float, long double>
00142 { typedef long double self; };
00143 template<> struct balanced_type<long double, double>
00144 { typedef long double self; };
00145 template<> struct balanced_type<double, long double>
00146 { typedef long double self; };
00147
00148
00149
00150
00151 template<> struct balanced_type<float, short> { typedef float self; };
00152 template<> struct balanced_type<short, float> { typedef float self; };
00153 template<> struct balanced_type<float, int> { typedef float self; };
00154 template<> struct balanced_type<int, float> { typedef float self; };
00155 template<> struct balanced_type<float, long> { typedef float self; };
00156 template<> struct balanced_type<long, float> { typedef float self; };
00157
00158 template<> struct balanced_type<double, short> { typedef double self; };
00159 template<> struct balanced_type<short, double> { typedef double self; };
00160 template<> struct balanced_type<double, int> { typedef double self; };
00161 template<> struct balanced_type<int, double> { typedef double self; };
00162 template<> struct balanced_type<double, long> { typedef double self; };
00163 template<> struct balanced_type<long, double> { typedef double self; };
00164
00165 template<> struct balanced_type<long double, short>
00166 { typedef long double self; };
00167 template<> struct balanced_type<short, long double>
00168 { typedef long double self; };
00169 template<> struct balanced_type<long double, int>
00170 { typedef long double self; };
00171 template<> struct balanced_type<int, long double>
00172 { typedef long double self; };
00173 template<> struct balanced_type<long double, long>
00174 { typedef long double self; };
00175 template<> struct balanced_type<long, long double>
00176 { typedef long double self; };
00177
00178 }}
00179
00180
00181
00182 #endif