comparison DEPENDENCIES/generic/include/boost/multiprecision/rational_adaptor.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
32 32
33 typedef typename IntBackend::signed_types signed_types; 33 typedef typename IntBackend::signed_types signed_types;
34 typedef typename IntBackend::unsigned_types unsigned_types; 34 typedef typename IntBackend::unsigned_types unsigned_types;
35 typedef typename IntBackend::float_types float_types; 35 typedef typename IntBackend::float_types float_types;
36 36
37 rational_adaptor(){} 37 rational_adaptor() BOOST_NOEXCEPT_IF(noexcept(rational_type())) {}
38 rational_adaptor(const rational_adaptor& o) 38 rational_adaptor(const rational_adaptor& o) BOOST_NOEXCEPT_IF(noexcept(std::declval<rational_type&>() = std::declval<const rational_type&>()))
39 { 39 {
40 m_value = o.m_value; 40 m_value = o.m_value;
41 } 41 }
42 rational_adaptor(const IntBackend& o) : m_value(o) {} 42 rational_adaptor(const IntBackend& o) BOOST_NOEXCEPT_IF(noexcept(rational_type(std::declval<const IntBackend&>()))) : m_value(o) {}
43 43
44 template <class U> 44 template <class U>
45 rational_adaptor(const U& u, typename enable_if_c<is_convertible<U, IntBackend>::value>::type* = 0) 45 rational_adaptor(const U& u, typename enable_if_c<is_convertible<U, IntBackend>::value>::type* = 0)
46 : m_value(IntBackend(u)){} 46 : m_value(static_cast<integer_type>(u)){}
47 template <class U> 47 template <class U>
48 explicit rational_adaptor(const U& u, 48 explicit rational_adaptor(const U& u,
49 typename enable_if_c< 49 typename enable_if_c<
50 boost::multiprecision::detail::is_explicitly_convertible<U, IntBackend>::value && !is_convertible<U, IntBackend>::value 50 boost::multiprecision::detail::is_explicitly_convertible<U, IntBackend>::value && !is_convertible<U, IntBackend>::value
51 >::type* = 0) 51 >::type* = 0)
55 { 55 {
56 m_value = IntBackend(u); 56 m_value = IntBackend(u);
57 } 57 }
58 58
59 #ifndef BOOST_NO_CXX11_RVALUE_REFERENCES 59 #ifndef BOOST_NO_CXX11_RVALUE_REFERENCES
60 rational_adaptor(rational_adaptor&& o) : m_value(o.m_value) {} 60 rational_adaptor(rational_adaptor&& o) BOOST_NOEXCEPT_IF(noexcept(rational_type(std::declval<rational_type>()))) : m_value(static_cast<rational_type&&>(o.m_value)) {}
61 rational_adaptor(IntBackend&& o) : m_value(o) {} 61 rational_adaptor(IntBackend&& o) BOOST_NOEXCEPT_IF(noexcept(rational_type(std::declval<IntBackend>()))) : m_value(static_cast<IntBackend&&>(o)) {}
62 rational_adaptor& operator = (rational_adaptor&& o) 62 rational_adaptor& operator = (rational_adaptor&& o) BOOST_NOEXCEPT_IF(noexcept(std::declval<rational_type&>() = std::declval<rational_type>()))
63 { 63 {
64 m_value = static_cast<rational_type&&>(o.m_value); 64 m_value = static_cast<rational_type&&>(o.m_value);
65 return *this; 65 return *this;
66 } 66 }
67 #endif 67 #endif
163 int compare(const rational_adaptor& o)const 163 int compare(const rational_adaptor& o)const
164 { 164 {
165 return m_value > o.m_value ? 1 : (m_value < o.m_value ? -1 : 0); 165 return m_value > o.m_value ? 1 : (m_value < o.m_value ? -1 : 0);
166 } 166 }
167 template <class Arithmatic> 167 template <class Arithmatic>
168 typename enable_if<is_arithmetic<Arithmatic>, int>::type compare(Arithmatic i)const 168 typename enable_if_c<is_arithmetic<Arithmatic>::value && !is_floating_point<Arithmatic>::value, int>::type compare(Arithmatic i)const
169 { 169 {
170 return m_value > i ? 1 : (m_value < i ? -1 : 0); 170 return m_value > i ? 1 : (m_value < i ? -1 : 0);
171 }
172 template <class Arithmatic>
173 typename enable_if_c<is_floating_point<Arithmatic>::value, int>::type compare(Arithmatic i)const
174 {
175 rational_adaptor r;
176 r = i;
177 return this->compare(r);
171 } 178 }
172 rational_type& data() { return m_value; } 179 rational_type& data() { return m_value; }
173 const rational_type& data()const { return m_value; } 180 const rational_type& data()const { return m_value; }
174 181
175 template <class Archive> 182 template <class Archive>
224 } 231 }
225 result.data() /= o.data(); 232 result.data() /= o.data();
226 } 233 }
227 234
228 template <class R, class IntBackend> 235 template <class R, class IntBackend>
229 inline void eval_convert_to(R* result, const rational_adaptor<IntBackend>& backend) 236 inline typename enable_if_c<number_category<R>::value == number_kind_floating_point>::type eval_convert_to(R* result, const rational_adaptor<IntBackend>& backend)
230 { 237 {
231 *result = backend.data().numerator().template convert_to<R>(); 238 //
232 *result /= backend.data().denominator().template convert_to<R>(); 239 // The generic conversion is as good as anything we can write here:
240 //
241 ::boost::multiprecision::detail::generic_convert_rational_to_float(*result, backend);
242 }
243
244 template <class R, class IntBackend>
245 inline typename enable_if_c<(number_category<R>::value != number_kind_integer) && (number_category<R>::value != number_kind_floating_point)>::type eval_convert_to(R* result, const rational_adaptor<IntBackend>& backend)
246 {
247 typedef typename component_type<number<rational_adaptor<IntBackend> > >::type comp_t;
248 comp_t num(backend.data().numerator());
249 comp_t denom(backend.data().denominator());
250 *result = num.template convert_to<R>();
251 *result /= denom.template convert_to<R>();
252 }
253
254 template <class R, class IntBackend>
255 inline typename enable_if_c<number_category<R>::value == number_kind_integer>::type eval_convert_to(R* result, const rational_adaptor<IntBackend>& backend)
256 {
257 typedef typename component_type<number<rational_adaptor<IntBackend> > >::type comp_t;
258 comp_t t = backend.data().numerator();
259 t /= backend.data().denominator();
260 *result = t.template convert_to<R>();
233 } 261 }
234 262
235 template <class IntBackend> 263 template <class IntBackend>
236 inline bool eval_is_zero(const rational_adaptor<IntBackend>& val) 264 inline bool eval_is_zero(const rational_adaptor<IntBackend>& val)
237 { 265 {