示例#1
0
	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
0
文件: values.hpp 项目: Fadis/Sprout
	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()
				)
			;
	}
示例#3
0
inline SPROUT_CONSTEXPR sprout::rational<IntType>
operator*(sprout::rational<IntType> const& lhs, sprout::rational<IntType> const& rhs) {
    return sprout::detail::rational_mul_impl(
               lhs, rhs,
               sprout::gcd(lhs.numerator(), rhs.denominator()),
               sprout::gcd(rhs.numerator(), lhs.denominator())
           );
}
示例#4
0
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
0
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())
           )
           ;
}
示例#6
0
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)
           );
}
示例#7
0
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)
           );
}
示例#8
0
		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()
					)
				;
		}
示例#9
0
	inline SPROUT_CONSTEXPR std::size_t
	hash_value(sprout::rational<T> const& v) {
		return sprout::hash_values(v.numerator(), v.denominator());
	}
示例#10
0
	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;
	}
示例#11
0
	inline SPROUT_CONSTEXPR bool
	operator==(sprout::rational<IntType> const& lhs, sprout::rational<IntType> const& rhs) {
		return lhs.numerator() == rhs.numerator() && lhs.denominator() == rhs.denominator();
	}
示例#12
0
	inline SPROUT_CONSTEXPR T
	rational_cast(sprout::rational<IntType> const& src) {
		return static_cast<T>(src.numerator()) / static_cast<T>(src.denominator());
	}