1 #ifndef __RATIONAL_HPP_ 2 #define __RATIONAL_HPP_ 4 #include "../gcd/gcd_template.hpp" 47 virtual bool is_one()
const override;
48 virtual bool is_zero()
const override;
90 :
num(numerator),
den(denominator)
189 ostream & operator << (ostream & os, const Rational<T> & r) {
190 os << r.get_numerator();
191 if (r.get_denominator() != 1)
192 os <<
" / " << r.get_denominator();
T den
the denominator
Definition: rational.hpp:23
virtual Ring_Element & operator-(const Ring_Element &) const override
subtraction: other element should be of same type, use a cast
Definition: rational.hpp:120
virtual bool is_zero() const override
should be True iff element is additive identity
Definition: rational.hpp:107
a field is an integral domain whose nonzero elements have inverses
Definition: rings.hpp:63
virtual bool is_cancellable() const override
integral domains are commutative rings without zero divisors, so the element should be cancellable (s...
Definition: rings.hpp:59
virtual Field_Element & inverse() const override
returns reciprocal
Definition: rational.hpp:173
a type for rational numbers
Definition: rational.hpp:16
virtual Field_Element & operator/(const Field_Element &) const override
division: other element should be of same type, use a cast
Definition: rational.hpp:140
Definition: integer.hpp:6
virtual bool is_one() const override
should be True iff element is multiplicative identity
Definition: rational.hpp:104
virtual Ring_Element & operator+(const Ring_Element &) const override
addition: other element should be of same type, use a cast
Definition: rational.hpp:110
encapsulates integers under the Ring_Element rubric
Definition: integer.hpp:17
Rational()
initializes to 0
Definition: rational.hpp:83
virtual bool is_commutative() const override
Duh.
Definition: rings.hpp:42
const Rational< T > & operator=(const Ring_Element &)
assignment operator may be needed
Definition: rational.hpp:151
a class for elements with the capabilities of ring arithmetic
Definition: rings.hpp:9
virtual bool has_inverse() const override
fields are integral domains where nonzero elements have inverses
Definition: rings.hpp:68
T get_numerator() const
returns the numerator
Definition: rational.hpp:179
void simplify()
uses the gcd to reduce num and denom (if necessary)
Definition: rational.hpp:72
virtual Ring_Element & operator*(const Ring_Element &) const override
multiplicationL other element should be of same type, use a cast
Definition: rational.hpp:130
virtual bool operator!=(const Ring_Element &) const override
comparison: other element has different value
Definition: rational.hpp:167
T get_denominator() const
returns the denominator
Definition: rational.hpp:182
T num
the numerator
Definition: rational.hpp:21
virtual bool operator==(const Ring_Element &) const override
comparison: other element has same value
Definition: rational.hpp:161