Boost C++ Libraries Home Libraries People FAQ More

PrevUpHomeNext

Rational Number Types

cpp_rational
gmp_rational
tommath_rational
Use With Boost.Rational
rational_adaptor

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_adaptor

boost/multiprecision/rational_adaptor.hpp

N/A

none

All C++ adaptor 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