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 #ifndef NTG_OPTRAITS_REAL_DEFS_HH
00029 # define NTG_OPTRAITS_REAL_DEFS_HH
00030
00031
00032
00033
00035
00036 # define ASSIGN_SCALAR_OPERATOR(Name) \
00037 template <class T1, class T2> inline \
00038 static T1& Name##_equal(T1& lhs, const T2& rhs) \
00039 { \
00040 ntg_is_a(T1, ntg::real)::ensure(); \
00041 ntg_is_a(T2, ntg::real)::ensure(); \
00042 \
00043 return Name##_equal_impl<T1,T2>(lhs, rhs); \
00044 } \
00045 \
00046 template <class T1, class T2> inline \
00047 static T1& \
00048 Name##_equal_impl(ntg::real_value<T1>& lhs, \
00049 const ntg::real_value<T2>& rhs) \
00050 { \
00051 typedef typename typetraits<T1>::behavior_type behavior_type; \
00052 lhs.exact() = behavior_type::check_##Name(lhs.exact().val(), \
00053 rhs.exact().val()); \
00054 return lhs.exact(); \
00055 } \
00056 \
00057 template <class T1, class T2> inline \
00058 static T1& \
00059 Name##_equal_impl(ntg::real_value<T1>& lhs, \
00060 const ntg::any_const_class<T2> rhs) \
00061 { \
00062 typedef typename typetraits<T1>::behavior_type behavior_type; \
00063 lhs.exact() = behavior_type::check_##Name(lhs.exact().val(), \
00064 rhs.exact()); \
00065 return lhs.exact(); \
00066 } \
00067 \
00068 template <class T1, class T2> inline \
00069 static T1& \
00070 Name##_equal_impl(ntg::any_class<T1> lhs, \
00071 const ntg::real_value<T2>& rhs) \
00072 { \
00073 typedef typename typetraits<T1>::behavior_type behavior_type; \
00074 lhs.exact() = behavior_type::check_##Name(lhs.exact(), \
00075 rhs.exact().val()); \
00076 return lhs.exact(); \
00077 }
00078
00079 # define ARITH_SCALAR_OPERATOR(Name) \
00080 template <class T1, class T2> inline \
00081 static ntg_return_type(Name, T1, T2) \
00082 Name(const T1& lhs, const T2& rhs) \
00083 { \
00084 ntg_is_a(T1, ntg::real)::ensure(); \
00085 ntg_is_a(T2, ntg::real)::ensure(); \
00086 \
00087 return Name##_impl<T1,T2>(lhs, rhs); \
00088 } \
00089 \
00090 template <class T1, class T2> inline \
00091 static ntg_return_type(Name, T1, T2) \
00092 Name##_impl(const ntg::real_value<T1>& lhs, \
00093 const ntg::real_value<T2>& rhs) \
00094 { \
00095 typedef ntg_return_type(Name, T1, T2) return_type; \
00096 typedef typename \
00097 typetraits<E>::abstract_behavior_type::get<return_type> \
00098 behavior_type; \
00099 return_type tmp; \
00100 tmp = behavior_type::check_##Name(lhs.exact().val(), \
00101 rhs.exact().val()); \
00102 return tmp; \
00103 } \
00104 \
00105 template <class T1, class T2> inline \
00106 static ntg_return_type(Name, T1, T2) \
00107 Name##_impl(const ntg::real_value<T1>& lhs, \
00108 const ntg::any_const_class<T2>& rhs) \
00109 { \
00110 typedef ntg_return_type(Name, T1, T2) return_type; \
00111 typedef typename \
00112 typetraits<E>::abstract_behavior_type::get<return_type> \
00113 behavior_type; \
00114 return_type tmp; \
00115 tmp = behavior_type::check_##Name(lhs.exact().val(), \
00116 rhs.exact()); \
00117 return tmp; \
00118 } \
00119 \
00120 template <class T1, class T2> inline \
00121 static ntg_return_type(Name, T1, T2) \
00122 Name##_impl(const ntg::any_const_class<T1>& lhs, \
00123 const ntg::real_value<T2>& rhs) \
00124 { \
00125 typedef ntg_return_type(Name, T1, T2) return_type; \
00126 typedef typename \
00127 typetraits<E>::abstract_behavior_type::get<return_type> \
00128 behavior_type; \
00129 return_type tmp; \
00130 tmp = behavior_type::check_##Name(lhs.exact(), \
00131 rhs.exact().val()); \
00132 return tmp; \
00133 }
00134
00135 # define CMP_SCALAR_OPERATOR(Name, Op) \
00136 template <class T1, class T2> inline \
00137 static bool Name (const T1& lhs, const T2& rhs) \
00138 { \
00139 ntg_is_a(T1, ntg::real)::ensure(); \
00140 ntg_is_a(T2, ntg::real)::ensure(); \
00141 \
00142 typedef ntg_return_type(cmp, T1, T2) tmp_type; \
00143 \
00144 return Name##_impl<tmp_type>(static_cast<tmp_type>(lhs), \
00145 static_cast<tmp_type>(rhs)); \
00146 } \
00147 \
00148 template <class T> inline \
00149 static bool \
00150 Name##_impl(const ntg::real_value<T>& lhs, \
00151 const ntg::real_value<T>& rhs) \
00152 { return lhs.exact().val() Op rhs.exact().val(); } \
00153 \
00154 template <class T> inline \
00155 static bool \
00156 Name##_impl(const ntg::any_const_class<T> lhs, \
00157 const ntg::any_const_class<T> rhs) \
00158 { return lhs.exact() Op rhs.exact(); }
00159
00160
00161
00162
00163
00165
00166 # define ASSIGN_INT_OPERATOR(Name, Op) \
00167 template <class T1, class T2> inline \
00168 static T1& Name(T1& lhs, const T2& rhs) \
00169 { \
00170 ntg_is_a(T1, ntg::integer)::ensure(); \
00171 ntg_is_a(T2, ntg::integer)::ensure(); \
00172 \
00173 return Name##_impl<T1,T2>(lhs, rhs); \
00174 } \
00175 \
00176 template <class T1, class T2> inline \
00177 static T1& Name##_impl(int_value<T1>& lhs, const int_value<T2>& rhs) \
00178 { \
00179 lhs.exact() = lhs.exact().val() Op rhs.exact().val(); \
00180 return lhs.exact(); \
00181 } \
00182 \
00183 template <class T1, class T2> inline \
00184 static T1& Name##_impl(int_value<T1>& lhs, \
00185 const ntg::any_const_class<T2>& rhs) \
00186 { \
00187 lhs.exact() = lhs.exact().val() Op rhs.exact(); \
00188 return lhs.exact(); \
00189 } \
00190 \
00191 template <class T1, class T2> inline \
00192 static T1& Name##_impl(ntg::any_class<T1>& lhs, \
00193 const int_value<T2>& rhs) \
00194 { \
00195 lhs.exact() = lhs.exact() Op rhs.exact().val(); \
00196 return lhs.exact(); \
00197 }
00198
00199 # define ARITH_INT_OPERATOR(Name, Op) \
00200 template <class T1, class T2> inline \
00201 static ntg_return_type(Name, T1, T2) \
00202 Name(const T1& lhs, const T2& rhs) \
00203 { \
00204 ntg_is_a(T1, integer)::ensure(); \
00205 ntg_is_a(T2, integer)::ensure(); \
00206 \
00207 typedef ntg_return_type(Name, T1, T2) return_type; \
00208 return_type result(lhs); \
00209 result Op rhs; \
00210 return result; \
00211 }
00212
00213 #endif // ndef NTG_OPTRAITS_REAL_DEFS_HH