本文整理汇总了C++中sprout::rational类的典型用法代码示例。如果您正苦于以下问题:C++ rational类的具体用法?C++ rational怎么用?C++ rational使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了rational类的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1:
inline SPROUT_CONSTEXPR bool
operator<(sprout::rational<IntType> const& lhs, typename sprout::rational<IntType>::param_type rhs) {
return sprout::detail::rational_less_impl(
lhs, rhs,
lhs.numerator() / lhs.denominator(), lhs.numerator() % lhs.denominator()
);
}
示例2:
inline SPROUT_CONSTEXPR sprout::rational<IntType>
operator+(sprout::rational<IntType> const& lhs, sprout::rational<IntType> const& rhs) {
return sprout::detail::rational_add_impl(
lhs, rhs,
sprout::gcd(lhs.denominator(), rhs.denominator())
);
}
示例3: abs
inline SPROUT_CONSTEXPR sprout::rational<IntType>
abs(sprout::rational<IntType> const& x) {
return x.numerator() >= IntType(0) ? x
: sprout::detail::rational_construct_access<IntType>::raw_construct(
-x.numerator(), x.denominator()
)
;
}
示例4: rational_add_impl_1
inline SPROUT_CONSTEXPR sprout::rational<IntType>
rational_add_impl_1(
sprout::rational<IntType> const& lhs, sprout::rational<IntType> const& rhs,
IntType g, IntType den
)
{
return rational_add_impl_2(
rhs,
g, den, lhs.numerator() * (rhs.denominator() / g) + rhs.numerator() * den
);
}
示例5: rational_div_impl
inline SPROUT_CONSTEXPR sprout::rational<IntType>
rational_div_impl(
sprout::rational<IntType> const& lhs, sprout::rational<IntType> const& rhs,
IntType gcd1, IntType gcd2
)
{
return sprout::detail::rational_div_impl_1(
(lhs.numerator() / gcd1) * (rhs.denominator() / gcd2),
(lhs.denominator() / gcd2) * (rhs.numerator() / gcd1)
);
}
示例6: rational_mul_impl
inline SPROUT_CONSTEXPR sprout::rational<IntType>
rational_mul_impl(
sprout::rational<IntType> const& lhs, sprout::rational<IntType> const& rhs,
IntType gcd1, IntType gcd2
)
{
return sprout::detail::rational_construct_access<IntType>::raw_construct(
(lhs.numerator() / gcd1) * (rhs.numerator() / gcd2),
(lhs.denominator() / gcd2) * (rhs.denominator() / gcd1)
);
}
示例7: rational_less_impl
inline SPROUT_CONSTEXPR bool
rational_less_impl(
sprout::rational<IntType> const& lhs, sprout::rational<IntType> const& rhs,
IntType d1, IntType q1, IntType r1
)
{
return r1 < IntType(0) ? sprout::detail::rational_less_impl(
lhs, rhs,
d1, q1 - 1, r1 + d1
)
: sprout::detail::rational_less_impl_1(
lhs, rhs,
d1, q1, r1,
rhs.denominator(), rhs.numerator() / rhs.denominator(), rhs.numerator() % rhs.denominator()
)
;
}
示例8: rational_add_impl_3
inline SPROUT_CONSTEXPR sprout::rational<IntType>
rational_add_impl_3(
sprout::rational<IntType> const& rhs,
IntType g, IntType den, IntType num
)
{
return sprout::detail::rational_construct_access<IntType>::raw_construct(
num / g, den * (rhs.denominator() / g)
);
}
示例9: rational_add_impl
inline SPROUT_CONSTEXPR sprout::rational<IntType>
rational_add_impl(
sprout::rational<IntType> const& lhs, sprout::rational<IntType> const& rhs,
IntType g
)
{
return rational_add_impl_1(
lhs, rhs,
g, lhs.denominator() / g
);
}
示例10: IntType
inline SPROUT_CONSTEXPR sprout::rational<IntType>
operator/(sprout::rational<IntType> const& lhs, sprout::rational<IntType> const& rhs) {
return rhs.numerator() == IntType(0) ? throw sprout::bad_rational()
: lhs.numerator() == IntType(0) ? lhs
: sprout::detail::rational_div_impl(
lhs, rhs,
sprout::gcd(lhs.numerator(), rhs.numerator()),
sprout::gcd(rhs.denominator(), lhs.denominator())
)
;
}
示例11: IntType
inline SPROUT_NON_CONSTEXPR std::basic_istream<Elem, Traits>&
operator>>(std::basic_istream<Elem, Traits>& lhs, sprout::rational<IntType>& rhs) {
IntType n = IntType(0);
IntType d = IntType(1);
Elem c = 0;
sprout::detail::io::ios_flags_saver saver(lhs);
lhs >> n;
c = lhs.get();
if (c != Elem('/')) {
lhs.clear(std::istream::badbit);
}
lhs >> std::noskipws;
lhs >> d;
if (lhs) {
rhs.assign(n, d);
}
return lhs;
}
示例12: hash_value
inline SPROUT_CONSTEXPR std::size_t
hash_value(sprout::rational<T> const& v) {
return sprout::hash_values(v.numerator(), v.denominator());
}
示例13: IntType
inline SPROUT_CONSTEXPR bool
operator==(sprout::rational<IntType> const& lhs, typename sprout::rational<IntType>::param_type rhs) {
return lhs.denominator() == IntType(1) && lhs.numerator() == rhs;
}
示例14: rational_cast
inline SPROUT_CONSTEXPR T
rational_cast(sprout::rational<IntType> const& src) {
return static_cast<T>(src.numerator()) / static_cast<T>(src.denominator());
}