rational

Adaptive, arbitrary precision decimal real with arithmetic exceptions

rational is an adaptive, arbitrary precision decimal sign-magnitude rational type.

The type definition for arbitrary precision rationals in Universal is:

class rational;

The rational type will dynamically adapt to the precision requirements of computation.

The rational type can be compiled with or without exceptions using a compile guard: RATIONAL_THROW_ARITHMETIC_EXCEPTION, to be set before including the type in your module, like so:

#define RATIONAL_THROW_ARITHMETIC_EXCEPTION 1
#include <universal/number/rational/rational.hpp>

By default, exceptions are not enabled. They are defined, but not thrown, so client code will work in either configuration.

The rational type is useful for arbitrary precision decimal real applications. It uses the decimal system to represent values, so it can accurately represent 0.1, or 10% of a monetary value.

Last updated