Rational numbers

Back to Real numbers

The rational numbers are an ordered field , where

Theory

It follows that:

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.

Practice

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:

Learn more