There are C++ libraries for arbitrary precision rational arithmetic, which allow you to perform calculations with rational numbers (fractions) of any size. Here are a few examples:
GMP is a popular open-source library for arbitrary precision arithmetic, including rational numbers. The rational number functionality is provided by the mpq class.
Boost.Multiprecision is a part of the Boost C++ Libraries, offering arbitrary precision arithmetic types, including rational numbers. The rational number type is rational.
MPLAPACK is a C++ library for high-precision numerical computations, including rational arithmetic. The rational number type is Rational.
CLN is a C++ library for exact computations, including rational numbers. The rational number type is Rational.
These libraries provide various features and trade-offs regarding performance, ease of use, and licensing. You can choose the one that best fits your project's requirements.
3. Available Operations for mpq_class From examining the implementation, here are the commonly available operations: Arithmetic operators: +, -, *, / (binary and unary -) +=, -=, *=, /= Comparison operators: ==, !=, <, >, <=, >= Member functions: .get_num(), .get_den() - get numerator/denominator as mpz_class .get_d() - convert to double .canonicalize() - normalize the fraction (usually automatic) Functions in: abs(mpq_class) sqrt(mpq_class) - returns mpf_class (floating-point) cmp(mpq_class, mpq_class)