예제 #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
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
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()
				)
			;
	}
예제 #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>
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
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)
           );
}
예제 #7
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()
					)
				;
		}
예제 #8
0
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
0
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
0
		inline SPROUT_CONSTEXPR bool
		rational_less_impl(
			sprout::rational<IntType> const& lhs, typename sprout::rational<IntType>::param_type rhs,
			IntType q, IntType r
			)
		{
			return r < IntType(0) ? sprout::detail::rational_less_impl(
					lhs, rhs,
					r + lhs.denominator(), q - 1
					)
				: q < rhs
				;
		}
예제 #11
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())
           )
           ;
}
예제 #12
0
파일: io.hpp 프로젝트: LoliGothick/Sprout
	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;
	}
예제 #13
0
파일: hash.hpp 프로젝트: LoliGothick/Sprout
	inline SPROUT_CONSTEXPR std::size_t
	hash_value(sprout::rational<T> const& v) {
		return sprout::hash_values(v.numerator(), v.denominator());
	}
예제 #14
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;
	}
예제 #15
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();
	}
예제 #16
0
	inline SPROUT_CONSTEXPR T
	rational_cast(sprout::rational<IntType> const& src) {
		return static_cast<T>(src.numerator()) / static_cast<T>(src.denominator());
	}