comparison DEPENDENCIES/generic/include/boost/ratio/ratio.hpp @ 101:c530137014c0

Update Boost headers (1.58.0)
author Chris Cannam
date Mon, 07 Sep 2015 11:12:49 +0100
parents 2665513ce2d3
children
comparison
equal deleted inserted replaced
100:793467b5e61c 101:c530137014c0
40 #include <cstdlib> 40 #include <cstdlib>
41 #include <climits> 41 #include <climits>
42 #include <limits> 42 #include <limits>
43 #include <boost/cstdint.hpp> 43 #include <boost/cstdint.hpp>
44 #include <boost/type_traits/integral_constant.hpp> 44 #include <boost/type_traits/integral_constant.hpp>
45 #include <boost/utility/enable_if.hpp> 45 #include <boost/core/enable_if.hpp>
46 #include <boost/integer_traits.hpp> 46 #include <boost/integer_traits.hpp>
47 #include <boost/ratio/ratio_fwd.hpp> 47 #include <boost/ratio/ratio_fwd.hpp>
48 #include <boost/ratio/detail/overflow_helpers.hpp> 48 #include <boost/ratio/detail/overflow_helpers.hpp>
49 #ifdef BOOST_RATIO_EXTENSIONS 49 #ifdef BOOST_RATIO_EXTENSIONS
50 #include <boost/rational.hpp> 50 #include <boost/rational.hpp>
126 const boost::intmax_t ratio<N, D>::den; 126 const boost::intmax_t ratio<N, D>::den;
127 #endif 127 #endif
128 128
129 //----------------------------------------------------------------------------// 129 //----------------------------------------------------------------------------//
130 // // 130 // //
131 // 20.6.2 Arithmetic on ratio types [ratio.arithmetic] // 131 // 20.6.2 Arithmetic on ratio types [ratio.arithmetic] //
132 // // 132 // //
133 //----------------------------------------------------------------------------// 133 //----------------------------------------------------------------------------//
134 134
135 template <class R1, class R2> 135 template <class R1, class R2>
136 struct ratio_add 136 struct ratio_add
156 { 156 {
157 }; 157 };
158 158
159 //----------------------------------------------------------------------------// 159 //----------------------------------------------------------------------------//
160 // // 160 // //
161 // 20.6.3 Comparasion of ratio types [ratio.comparison] // 161 // 20.6.3 Comparision of ratio types [ratio.comparison] //
162 // // 162 // //
163 //----------------------------------------------------------------------------// 163 //----------------------------------------------------------------------------//
164 164
165 // ratio_equal 165 // ratio_equal
166 166
202 ratio<mpl::gcd_c<boost::intmax_t, R1::num, R2::num>::value, 202 ratio<mpl::gcd_c<boost::intmax_t, R1::num, R2::num>::value,
203 mpl::lcm_c<boost::intmax_t, R1::den, R2::den>::value>::type 203 mpl::lcm_c<boost::intmax_t, R1::den, R2::den>::value>::type
204 { 204 {
205 }; 205 };
206 206
207 //----------------------------------------------------------------------------//
208 // //
209 // More arithmetic on ratio types [ratio.arithmetic] //
210 // //
211 //----------------------------------------------------------------------------//
212
207 #ifdef BOOST_RATIO_EXTENSIONS 213 #ifdef BOOST_RATIO_EXTENSIONS
208 template <class R> 214 template <class R>
209 struct ratio_negate 215 struct ratio_negate
210 : ratio<-R::num, R::den>::type 216 : ratio<-R::num, R::den>::type
211 { 217 {
218 template <class R> 224 template <class R>
219 struct ratio_sign 225 struct ratio_sign
220 : mpl::sign_c<boost::intmax_t, R::num> 226 : mpl::sign_c<boost::intmax_t, R::num>
221 { 227 {
222 }; 228 };
229
230 template <class R>
231 struct ratio_inverse
232 : ratio<R::den, R::num>::type
233 {
234 };
235
236
223 template <class R1, class R2> 237 template <class R1, class R2>
224 struct ratio_lcm : 238 struct ratio_lcm :
225 ratio<mpl::lcm_c<boost::intmax_t, R1::num, R2::num>::value, 239 ratio<mpl::lcm_c<boost::intmax_t, R1::num, R2::num>::value,
226 mpl::gcd_c<boost::intmax_t, R1::den, R2::den>::value>::type 240 mpl::gcd_c<boost::intmax_t, R1::den, R2::den>::value>::type
227 { 241 {
228 }; 242 };
243
244 template <class R1, class R2>
245 struct ratio_modulo :
246 ratio<(R1::num * R2::den) % (R2::num * R1::den), R1::den * R2::den>::type
247 {
248 };
249
250 namespace detail {
251 template <class R1, class R2, bool r1ltr2>
252 struct ratio_min : R1 {};
253 template <class R1, class R2>
254 struct ratio_min<R1,R2,false> : R2 {};
255
256 template <class R1, class R2, bool r1ltr2>
257 struct ratio_max : R2 {};
258 template <class R1, class R2>
259 struct ratio_max<R1,R2,false> : R1 {};
260 }
261
262 template <class R1, class R2>
263 struct ratio_min : detail::ratio_min<R1, R2, ratio_less<R1,R2>::value>::type
264 {
265 };
266
267 template <class R1, class R2>
268 struct ratio_max : detail::ratio_max<R1, R2, ratio_less<R1,R2>::value>::type
269 {
270 };
271
272 template<typename R, int p>
273 struct ratio_power :
274 ratio_multiply<
275 typename ratio_power<R, p%2>::type,
276 typename ratio_power<typename ratio_multiply<R, R>::type, p/2>::type
277 >::type
278 {};
279
280 template<typename R>
281 struct ratio_power<R, 0> : ratio<1>::type {};
282
283 template<typename R>
284 struct ratio_power<R, 1> : R {};
285
286 template<typename R>
287 struct ratio_power<R, -1> : ratio_divide<ratio<1>, R>::type {};
288
229 #endif 289 #endif
230 } // namespace boost 290 } // namespace boost
231 291
232 292
233 #endif // BOOST_RATIO_RATIO_HPP 293 #endif // BOOST_RATIO_RATIO_HPP