Boost C++ Libraries

...one of the most highly regarded and expertly designed C++ library projects in the world. Herb Sutter and Andrei Alexandrescu, C++ Coding Standards

This is the documentation for an old version of Boost. Click here to view this page for the latest version.
PrevUpHomeNext

Rational Number Types

cpp_rational
gmp_rational
tommath_rational
Use With Boost.Rational
rational_adapter

The following back-ends provide rational number arithmetic:

Backend Type

Header

Radix

Dependencies

Pros

Cons

cpp_rational

boost/multiprecision/cpp_int.hpp

2

None

An all C++ Boost-licensed implementation.

Slower than GMP.

gmp_rational

boost/multiprecision/gmp.hpp

2

GMP

Very fast and efficient back-end.

Dependency on GNU licensed GMP library.

tommath_rational

boost/multiprecision/tommath.hpp

2

libtommath

All C/C++ implementation that's Boost Software Licence compatible.

Slower than GMP.

rational_adapter

boost/multiprecision/rational_adapter.hpp

N/A

none

All C++ adapter that allows any integer back-end type to be used as a rational type.

Requires an underlying integer back-end type.

boost::rational

boost/rational.hpp

N/A

None

A C++ rational number type that can used with any number integer type.

The expression templates used by number end up being "hidden" inside boost::rational: performance may well suffer as a result.


PrevUpHomeNext