The rational numbers are an ordered field , where
( is an equivalence relation).
( means the equivalence class of )
It follows that:
is the multiplicative identity element.
is the additive identity element.
The subset consisting of the elements is isomorphic to the ordered ring of integers.
Most often, one works with the elements of , rather than with the rational numbers themselves. It must then be remembered that the corresponding equivalence classes are implicitly meant instead.
The Rational
class template can be used in conjuction with
integer types to provide a rational number. Rationals
have the potential to provide exact arithmetic under restricted
situations.
template <typename Integer>
class Rational;
There are several values with a special meaning:
It holds that:
Thus we can simply speak of Infinity and -Infinity.
The Rational
class maintains two invariants: