本文整理汇总了C++中rational::denominator方法的典型用法代码示例。如果您正苦于以下问题:C++ rational::denominator方法的具体用法?C++ rational::denominator怎么用?C++ rational::denominator使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类rational
的用法示例。
在下文中一共展示了rational::denominator方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: result
rational operator - (const rational &left, const rational &right)
{
rational result(
left.numerator() * right.denominator() -
right.numerator() * left.denominator(),
left.denominator() * right.denominator());
return result;
}
示例2: squareRoot
// **** 1.Add a square root function to the rational class. ****
rational squareRoot(const rational &r)
{
assert(r.numerator()>0);
double top = r.numerator();
double bot = r.denominator();
double topSqrt = sqrt(top);
double botSqrt = sqrt(bot);
// Estimate if not a perfect square
if ((fmod(topSqrt,1)!=0) ||(fmod(botSqrt,1)!=0))
{
topSqrt = sqrt(100*top);
botSqrt = sqrt(100*bot);
}
return rational((int)topSqrt, (int)botSqrt);
}
示例3: invert
// Other functions - not members or friends
rational invert(const rational &r)
{
assert( r.numerator() != 0 );
return rational(r.denominator(), r.numerator());
}
示例4: return
bool operator == (const rational &left, const rational &right)
{
return (left.numerator() * right.denominator() ==
left.denominator() * right.numerator());
}
示例5:
inline SPROUT_CONSTEXPR sprout::rational<IntType>
operator-(rational<IntType> const& r) {
return sprout::detail::rational_construct_access<IntType>::raw_construct(
-r.numerator(), r.denominator()
);
}
示例6:
// Assignments
void rational::operator = (const rational &right)
{
top = right.numerator();
bottom = right.denominator();
}
示例7: main
int main() {
constexpr rational<int> test(4, 2);
constexpr rational<int> normal = normalised(test);
static_assert(normal.numerator() == 2 && normal.denominator() == 1, "...");
}
示例8: abs
rational abs(rational const& r) {
return rational(std::abs(r.numerator()), r.denominator());
}
示例9:
bool operator<(rational const& a, rational const& b) {
return a.numerator() * b.denominator() < b.numerator() * a.denominator();
}
示例10: normalised
constexpr rational<Integer> normalised(const rational<Integer>& r) noexcept {
return r.numerator() == 0 ? rational<Integer>{ 0, 1 } :
rational<Integer>{ r.numerator() / gcd(r.numerator(), r.denominator()),
r.denominator() / gcd(r.numerator(), r.denominator()) };
}
示例11: rational
BOOST_CONSTEXPR explicit
rational(rational<NewType> const &r)
: num(r.numerator()), den(is_normalized(int_type(r.numerator()),
int_type(r.denominator())) ? r.denominator() :
(BOOST_THROW_EXCEPTION(bad_rational("bad rational: denormalized conversion")), 0)){}
示例12:
bool operator==(const rational<T2> &f) const
{
return ((this->_numerator == f.numerator()) &&
(this->_denominator == f.denominator()));
}
示例13:
inline rational<IntType> operator- (const rational<IntType>& r)
{
return rational<IntType>(-r.numerator(), r.denominator());
}
示例14: operator
//! @Returns the target rational having as numerator and denominator the conversion from the numerator and denominator of the source rational.
rational<Target> operator()(rational<Source> const & from)
{
return rational<Target>(boost::conversion::convert_to<Target>(from.numerator()), boost::conversion::convert_to<Target>(from.denominator()));
}